public static Map < String , String > parseTags ( final String tagString ) throws IllegalArgumentException { // delimit by whitespace or '=' Scanner scanner = new Scanner ( tagString ) . useDelimiter ( "\\s+|=" ) ; Map < String , String > tagMap = new HashMap < String , String > ( ) ; try { while ( scanner . hasNext ( ) ) { String tagName = scanner . next ( ) ; String tagValue = scanner . next ( ) ; tagMap . put ( tagName , tagValue ) ; } } catch ( NoSuchElementException e ) { // The tag string is corrupted. throw new IllegalArgumentException ( "Invalid tag string '" + tagString + "'" ) ; } finally { scanner . close ( ) ; } return tagMap ; }
Convert a tag string into a tag map .