Class 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 Detail

      • SimpleMapParser

        public SimpleMapParser()
    • 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
      • handleKeyValue

        protected abstract void handleKeyValue​(String key,
                                               String value)