Class ParameterMap<P,T>

java.lang.Object
org.apache.commons.chain.web.ParameterMap<P,T>
Type Parameters:
P - the type of the parameter-provider
T - the type of results supplied by this parameters
All Implemented Interfaces:
Map<String,T>
Direct Known Subclasses:
MutableParameterMap, ParamValuesMap

public class ParameterMap<P,T> extends Object implements Map<String,T>
Implementation of Map for immutable parameters with a parameter-provider.
Since:
Chain 1.3
Author:
Graff Stefan
  • Constructor Details

    • ParameterMap

      public ParameterMap(P parameter, Function<String,T> valueFunction, Supplier<Enumeration<String>> namesSupplier)
      The constructor for an immutable parameter-map.
      Parameters:
      parameter - the parameter-provider
      valueFunction - Function to return the value of a parameter
      namesSupplier - Supplier to return all names of the parameter
  • Method Details

    • clear

      public void clear()
      Removes all of the mappings from this parameter-map. The parameter-map will be empty after this call returns.
      Specified by:
      clear in interface Map<P,T>
      Throws:
      UnsupportedOperationException - because it is an immutable parameter-map
    • containsKey

      public boolean containsKey(Object key)
      Returns true if this parameter-map contains a mapping for the specified key.
      Specified by:
      containsKey in interface Map<P,T>
      Parameters:
      key - The key whose presence in this parameter-map is to be tested
      Returns:
      true if this parameter-map contains a mapping for the specified key.
    • containsValue

      public boolean containsValue(Object value)
      Returns true if this parameter-map maps one or more keys to the specified value.
      Specified by:
      containsValue in interface Map<P,T>
      Parameters:
      value - value whose presence in this parameter-map is to be tested
      Returns:
      true if this parameter-map maps one or more keys to the specified value
    • entrySet

      Returns a Set view of the mappings contained in this parameter-map. The set is not backed by the parameter-map, so changes to the parameter-map are not reflected in the set, and vice-versa.
      Specified by:
      entrySet in interface Map<P,T>
      Returns:
      a set view of the mappings contained in this parameter-map
    • get

      public T get(Object key)
      Returns the value to which the specified key is mapped, or null if this parameter-map contains no mapping for the key.

      A return value of null does not necessarily indicate that the parameter-map contains no mapping for the key; it's also possible that the parameter-map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

      Specified by:
      get in interface Map<P,T>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this parameter-map contains no mapping for the key
      See Also:
    • isEmpty

      public boolean isEmpty()
      Returns true if this parameter-map contains no key-value mappings.
      Specified by:
      isEmpty in interface Map<P,T>
      Returns:
      true if this parameter-map contains no key-value mappings
    • keySet

      public Set<String> keySet()
      Returns a Set view of the keys contained in this parameter-map. The set is not backed by the parameter-map, so changes to the parameter-map are not reflected in the set, and vice-versa.
      Specified by:
      keySet in interface Map<P,T>
      Returns:
      a set view of the keys contained in this parameter-map
    • put

      public T put(String key, T value)
      Associates the specified value with the specified key in this parameter-map. If the parameter-map previously contained a mapping for the key, the old value is replaced.
      Specified by:
      put in interface Map<P,T>
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Returns:
      the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the parameter-map previously associated null with key.)
      Throws:
      UnsupportedOperationException - because it is an immutable parameter-map
    • putAll

      public void putAll(Map<? extends String,? extends T> map)
      Copies all of the mappings from the specified map to this parameter-map. These mappings will replace any mappings that this parameter-map had for any of the keys currently in the specified map.
      Specified by:
      putAll in interface Map<P,T>
      Parameters:
      map - mappings to be stored in this parameter-map
      Throws:
      NullPointerException - if the specified map is null
      UnsupportedOperationException - because it is an immutable parameter-map
    • remove

      public T remove(Object key)
      Removes the mapping for the specified key from this parameter-map if present.
      Specified by:
      remove in interface Map<P,T>
      Parameters:
      key - key whose mapping is to be removed from the parameter-map
      Returns:
      the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the parameter-map previously associated null with key.)
      Throws:
      UnsupportedOperationException - because it is an immutable parameter-map
    • size

      public int size()
      Returns the number of key-value mappings in this parameter-map.
      Specified by:
      size in interface Map<P,T>
      Returns:
      the number of key-value mappings in this parameter-map
    • values

      public Collection<T> values()
      Returns a Collection view of the values contained in this parameter-map. The collection is not backed by the parameter-map, so changes to the parameter-map are not reflected in the collection, and vice-versa.
      Specified by:
      values in interface Map<P,T>
      Returns:
      a view of the values contained in this parameter-map
    • hashCode

      public int hashCode()
      Returns the hash code value for this parameter-map. The hash code of a parameter-map is defined to be the sum of the hash codes of each entry in the parameter-map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two parameter-maps m1 and m2, as required by the general contract of Object.hashCode().
      Specified by:
      hashCode in interface Map<P,T>
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this parameter-map
      Implementation Requirements:
      This implementation calls the hashCode() from the parameter-provider.
    • equals

      public boolean equals(Object obj)
      Compares the specified object with this parameter-map for equality. Returns true if the given object is also a parameter-map and the two parameter-maps represent the same mappings. More formally, two parameter-maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()).
      Specified by:
      equals in interface Map<P,T>
      Overrides:
      equals in class Object
      Parameters:
      obj - object to be compared for equality with this parameter-map
      Returns:
      true if the specified object is equal to this parameter-map
      Implementation Requirements:
      This implementation first checks if the specified object is this parameter-map; if so it returns true. Then, it checks if the specified object is the identical class this parameter-map; if not, it returns false. If so, it calls the equals() from the parameter-provider and returns its return-code.
    • toString

      public String toString()
      Returns a string representation of this parameter-map. The string representation consists of a list of key-value mappings in the order returned by the parameter-map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are converted to strings as by String.valueOf(Object).
      Overrides:
      toString in class Object
      Returns:
      a string representation of this parameter-map
    • getParameter

      protected P getParameter()
      Returns the parameter-class.
      Returns:
      the parameter-class
    • getValueFunction

      Returns the Function to return the value of a parameter as an String, or null if no parameter of the given name exists.
      Returns:
      the Function to return the value
    • getNamesSupplier

      Returns the Supplier to return an Enumeration of String objects containing the names of the parameters contained in this object.
      Returns:
      Supplier to return an Enumeration with all names of the parameters
    • entrySet

      protected Set<Map.Entry<String,T>> entrySet(boolean modifiable)
      Returns a Set view of the mappings contained in this map.
      Parameters:
      modifiable - Whether the entries should allow modification or not
      Returns:
      a set view of the mappings contained in this map
    • key

      protected static String key(Object key)
      Converts the key to a String.
      Parameters:
      key - the key
      Returns:
      the key as String