Class SimpleMapParser

  • Direct Known Subclasses:
    MapParser

    public abstract class SimpleMapParser
    extends java.lang.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.

    Since:
    5.1.15
    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​(java.lang.String key)  
      protected int findEndOfKey()  
      protected int findEndOfValue()  
      protected abstract void handleKeyValue​(java.lang.String key, java.lang.String value)  
      void parse​(java.lang.String string)
      Parses a map on the form {key1:value1,key2:value2 ...}
      PositionedString string()
      Returns the string being parsed along with its current position
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleMapParser

        public SimpleMapParser()
    • Method Detail

      • parse

        public void parse​(java.lang.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​(java.lang.String key)
      • string

        public PositionedString string()
        Returns the string being parsed along with its current position
      • handleKeyValue

        protected abstract void handleKeyValue​(java.lang.String key,
                                               java.lang.String value)