Package com.yahoo.text
Class MapParser<VALUETYPE>
java.lang.Object
com.yahoo.text.SimpleMapParser
com.yahoo.text.MapParser<VALUETYPE>
Superclasses of parsers of a map represented textually as
{key1:value1,"anystringkey":value2,'anystringkey2':value3 ...}.
This parser must be extended to override the way values are parsed and constructed.
Example: To create a Double map parser:
public static final class DoubleMapParser extends MapParser<Double> {
@Override
protected Double parseValue(String value) {
return Double.parseDouble(value);
}
}
Map parsers are NOT multithread safe, but are cheap to construct.
- Author:
- bratseth
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidhandleKeyValue(String key, String value) Parses a map on the form{key1:value1,key2:value2 ...}parseToMap(String s) Convenience method doing return parse(s,new HashMap<String,VALUETYPE>())protected abstract VALUETYPEparseValue(String value) Methods inherited from class com.yahoo.text.SimpleMapParser
consumeValue, findEndOfKey, findEndOfValue, parse, string
-
Constructor Details
-
MapParser
public MapParser()
-
-
Method Details
-
parseToMap
Convenience method doing return parse(s,new HashMap<String,VALUETYPE>()) -
parse
Parses a map on the form{key1:value1,key2:value2 ...}- Parameters:
string- the textual representation of the mapmap- the map to which the values will be added- Returns:
- the input map instance for convenience
-
handleKeyValue
- Specified by:
handleKeyValuein classSimpleMapParser
-
parseValue
-