Class MapParser<T>

java.lang.Object
org.simpleframework.common.parse.Parser
org.simpleframework.common.parse.MapParser<T>
All Implemented Interfaces:
Map<T,T>
Direct Known Subclasses:
QueryParser

public abstract class MapParser<T> extends Parser implements Map<T,T>
The MapParser object represents a parser for name value pairs. Any parser extending this will typically be parsing name=value tokens or the like, and inserting these pairs into the internal map. This type of parser is useful as it exposes all pairs extracted using the java.util.Map interface and as such can be used with the Java collections framework. The internal map used by this is a Hashtable, however subclasses are free to assign a different type to the map used.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface java.util.Map

    Map.Entry<K,V>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Map<T,List<T>>
    Represents all values inserted to the map as a list of values.
    protected Map<T,T>
    Represents the last value inserted into this map instance.

    Fields inherited from class org.simpleframework.common.parse.Parser

    buf, count, off
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor for the MapParser object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    The clear method is used to wipe out all the currently existing tokens from the collection.
    boolean
    This is used to determine whether a token representing the name of a pair has been inserted into the internal map.
    boolean
    This method is used to determine whether any pair that has been inserted into the internal map had the presented value.
    This method is used to acquire the name and value pairs that have currently been collected by this parser.
    get(Object name)
    The get method is used to acquire the value for a named pair.
    This method is used to acquire a List for all of the values that have been put in to the map.
    boolean
    This method is used to determine whether the parser has any tokens available.
    This is used to acquire the names for all the tokens that have currently been collected by this parser.
    put(T name, T value)
    The put method is used to insert the name and value provided into the collection of tokens.
    void
    putAll(Map<? extends T,? extends T> data)
    This method is used to insert a collection of tokens into the parsers map.
    remove(Object name)
    The remove method is used to remove the named token pair from the collection of tokens.
    int
    This obviously enough provides the number of tokens that have been inserted into the internal map.
    This method is used to acquire the value for all tokens that have currently been collected by this parser.

    Methods inherited from class org.simpleframework.common.parse.Parser

    digit, ensureCapacity, init, parse, parse, skip, space, toLower

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • all

      protected Map<T,List<T>> all
      Represents all values inserted to the map as a list of values.
    • map

      protected Map<T,T> map
      Represents the last value inserted into this map instance.
  • Constructor Details

    • MapParser

      protected MapParser()
      Constructor for the MapParser object. This is used to create a new parser that makes use of a thread safe map implementation. The HashMap is used so that the resulting parser can be accessed in a concurrent environment with the fear of data corruption.
  • Method Details

    • containsKey

      public boolean containsKey(Object name)
      This is used to determine whether a token representing the name of a pair has been inserted into the internal map. The object passed into this method should be a string, as all tokens stored within the map will be stored as strings.
      Specified by:
      containsKey in interface Map<T,T>
      Parameters:
      name - this is the name of a pair within the map
      Returns:
      this returns true if the pair of that name exists
    • containsValue

      public boolean containsValue(Object value)
      This method is used to determine whether any pair that has been inserted into the internal map had the presented value. If one or more pairs within the collected tokens contains the value provided then this method will return true.
      Specified by:
      containsValue in interface Map<T,T>
      Parameters:
      value - this is the value that is to be searched for
      Returns:
      this returns true if any value is equal to this
    • entrySet

      public Set<Map.Entry<T,T>> entrySet()
      This method is used to acquire the name and value pairs that have currently been collected by this parser. This is used to determine which tokens have been extracted from the source. It is useful when the tokens have to be gathered.
      Specified by:
      entrySet in interface Map<T,T>
      Returns:
      this set of token pairs that have been extracted
    • get

      public T get(Object name)
      The get method is used to acquire the value for a named pair. So if a pair of name=value has been parsed and inserted into the collection of tokens this will return the value given the name. The value returned will be a string.
      Specified by:
      get in interface Map<T,T>
      Parameters:
      name - this is a string used to search for the value
      Returns:
      this is the value, as a string, that has been found
    • getAll

      public List<T> getAll(Object key)
      This method is used to acquire a List for all of the values that have been put in to the map. The list allows all values associated with the specified key. This enables a parser to collect a number of associated tokens.
      Parameters:
      key - this is the key used to search for the value
      Returns:
      this is the list of values associated with the key
    • isEmpty

      public boolean isEmpty()
      This method is used to determine whether the parser has any tokens available. If the size is zero then the parser is empty and this returns true. The is acts as a proxy the the isEmpty of the internal map.
      Specified by:
      isEmpty in interface Map<T,T>
      Returns:
      this is true if there are no available tokens
    • keySet

      public Set<T> keySet()
      This is used to acquire the names for all the tokens that have currently been collected by this parser. This is used to determine which tokens have been extracted from the source. It is useful when the tokens have to be gathered.
      Specified by:
      keySet in interface Map<T,T>
      Returns:
      the set of name tokens that have been extracted
    • put

      public T put(T name, T value)
      The put method is used to insert the name and value provided into the collection of tokens. Although it is up to the parser to decide what values will be inserted it is generally the case that the inserted tokens will be text.
      Specified by:
      put in interface Map<T,T>
      Parameters:
      name - this is the name token from a name=value pair
      value - this is the value token from a name=value pair
      Returns:
      this returns the previous value if there was any
    • putAll

      public void putAll(Map<? extends T,? extends T> data)
      This method is used to insert a collection of tokens into the parsers map. This is used when another source of tokens is required to populate the connection currently maintained within this parsers internal map. Any tokens that currently exist with similar names will be overwritten by this.
      Specified by:
      putAll in interface Map<T,T>
      Parameters:
      data - this is the collection of tokens to be added
    • remove

      public T remove(Object name)
      The remove method is used to remove the named token pair from the collection of tokens. This acts like a take, in that it will get the token value and remove if from the collection of tokens the parser has stored.
      Specified by:
      remove in interface Map<T,T>
      Parameters:
      name - this is a string used to search for the value
      Returns:
      this is the value, as a string, that is removed
    • size

      public int size()
      This obviously enough provides the number of tokens that have been inserted into the internal map. This acts as a proxy method for the internal map size.
      Specified by:
      size in interface Map<T,T>
      Returns:
      this returns the number of tokens are available
    • values

      public Collection<T> values()
      This method is used to acquire the value for all tokens that have currently been collected by this parser. This is used to determine which tokens have been extracted from the source. It is useful when the tokens have to be gathered.
      Specified by:
      values in interface Map<T,T>
      Returns:
      the list of value tokens that have been extracted
    • clear

      public void clear()
      The clear method is used to wipe out all the currently existing tokens from the collection. This is used to recycle the parser so that it can be used to parse some other source of tokens without any lingering state.
      Specified by:
      clear in interface Map<T,T>