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.
Modifier and Type | Field and Description |
---|---|
private PositionedString |
s |
Constructor and Description |
---|
SimpleMapParser() |
Modifier and Type | Method and Description |
---|---|
private String |
consumeKey() |
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
|
private PositionedString s
public void parse(String string)
{key1:value1,key2:value2 ...}
string
- the textual representation of the mapprivate String consumeKey()
protected int findEndOfKey()
protected int findEndOfValue()
protected void consumeValue(String key)
public PositionedString string()
Copyright © 2017. All rights reserved.