Package com.yahoo.text
Class SimpleMapParser
- java.lang.Object
-
- com.yahoo.text.SimpleMapParser
-
- Direct Known Subclasses:
MapParser
public abstract class SimpleMapParser extends Object
Superclasses of parsers of a map represented textually as
{key1:value1,"anystringkey":value2,'anystringkey2':value3 ...}
. This parser must be extended to specify how to handle the key/value pairs.Example: To create a Double map parser:
public static final class DoubleMapParser extends MapParser<Double> { private Map<String, Double> map; ... @Override protected Double handleKeyValue(String key, String value) { map.put(key, Double.parseDouble(value)); } }
Map parsers are NOT multithread safe, but are cheap to construct.
- Author:
- bratseth
-
-
Constructor Summary
Constructors Constructor Description SimpleMapParser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
consumeValue(String key)
protected int
findEndOfKey()
protected int
findEndOfValue()
protected abstract void
handleKeyValue(String key, String value)
void
parse(String string)
Parses a map on the form{key1:value1,key2:value2 ...}
PositionedString
string()
Returns the string being parsed along with its current position
-
-
-
Method Detail
-
parse
public void parse(String string)
Parses a map on the form{key1:value1,key2:value2 ...}
- Parameters:
string
- the textual representation of the map
-
findEndOfKey
protected int findEndOfKey()
-
findEndOfValue
protected int findEndOfValue()
-
consumeValue
protected void consumeValue(String key)
-
string
public PositionedString string()
Returns the string being parsed along with its current position
-
-