Class LocalAttributeMap<V>

java.lang.Object
org.springframework.webflow.core.collection.LocalAttributeMap<V>
All Implemented Interfaces:
Serializable, MapAdaptable<String,V>, AttributeMap<V>, MutableAttributeMap<V>
Direct Known Subclasses:
LocalSharedAttributeMap

public class LocalAttributeMap<V> extends Object implements MutableAttributeMap<V>, Serializable
A generic, mutable attribute map with string keys.
Author:
Keith Donald
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new attribute map, initially empty.
    LocalAttributeMap(int size, int loadFactor)
    Creates a new attribute map, initially empty.
    LocalAttributeMap(String attributeName, V attributeValue)
    Creates a new attribute map with a single entry.
    Creates a new attribute map wrapping the specified map.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns this object's contents as a Map.
    Remove all attributes in this map.
    boolean
    contains(String attributeName)
    Does the attribute with the provided name exist in this map?
    boolean
    contains(String attributeName, Class<? extends V> requiredType)
    Does the attribute with the provided name exist in this map and is its value of the specified required type?
    protected Map<String,V>
    Factory method that returns the target map storing the data in this attribute map.
    protected Map<String,V>
    createTargetMap(int size, int loadFactor)
    Factory method that returns the target map storing the data in this attribute map.
    boolean
     
    extract(String attributeName)
    Extract an attribute from this map, getting it and removing it in a single operation.
    get(String attributeName)
    Get an attribute value out of this map, returning null if not found.
    <T extends V>
    T
    get(String attributeName, Class<T> requiredType)
    Get an attribute value, asserting the value is of the required type.
    <T extends V>
    T
    get(String attributeName, Class<T> requiredType, T defaultValue)
    Get an attribute value, asserting the value is of the required type and returning the default value if not found.
    get(String attributeName, V defaultValue)
    Get an attribute value, returning the default value if no value is found.
    <T extends V>
    T[]
    getArray(String attributeName, Class<? extends T[]> requiredType)
    Returns an array attribute value in the map and makes sure it is of the required type.
    getBoolean(String attributeName)
    Returns a boolean attribute value in the map, returning null if no value was found.
    getBoolean(String attributeName, Boolean defaultValue)
    Returns a boolean attribute value in the map, returning the default value if no value was found.
    getCollection(String attributeName)
    Returns a collection attribute value in the map.
    <T extends Collection<V>>
    T
    getCollection(String attributeName, Class<T> requiredType)
    Returns a collection attribute value in the map and make sure it is of the required type.
    getInteger(String attributeName)
    Returns an integer attribute value in the map, returning null if no value was found.
    getInteger(String attributeName, Integer defaultValue)
    Returns an integer attribute value in the map, returning the default value if no value was found.
    getLong(String attributeName)
    Returns a long attribute value in the map, returning null if no value was found.
    getLong(String attributeName, Long defaultValue)
    Returns a long attribute value in the map, returning the default value if no value was found.
    protected Map<String,V>
    Returns the wrapped, modifiable map implementation.
    <T extends Number>
    T
    getNumber(String attributeName, Class<T> requiredType)
    Returns a number attribute value in the map that is of the specified type, returning null if no value was found.
    <T extends Number>
    T
    getNumber(String attributeName, Class<T> requiredType, T defaultValue)
    Returns a number attribute value in the map of the specified type, returning the default value if no value was found.
    getRequired(String attributeName)
    Get the value of a required attribute, throwing an exception of no attribute is found.
    <T extends V>
    T
    getRequired(String attributeName, Class<T> requiredType)
    Get the value of a required attribute and make sure it is of the required type.
    <T extends V>
    T[]
    getRequiredArray(String attributeName, Class<? extends T[]> requiredType)
    Returns an array attribute value in the map, throwing an exception if the attribute is not present or not an array of the required type.
    getRequiredBoolean(String attributeName)
    Returns a boolean attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
    Returns a collection attribute value in the map, throwing an exception if the attribute is not present or not a collection.
    <T extends Collection<V>>
    T
    getRequiredCollection(String attributeName, Class<T> requiredType)
    Returns a collection attribute value in the map, throwing an exception if the attribute is not present or not a collection of the required type.
    getRequiredInteger(String attributeName)
    Returns an integer attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
    getRequiredLong(String attributeName)
    Returns a long attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
    <T extends Number>
    T
    getRequiredNumber(String attributeName, Class<T> requiredType)
    Returns a number attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
    getRequiredString(String attributeName)
    Returns a string attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
    getString(String attributeName)
    Returns a string attribute value in the map, returning null if no value was found.
    getString(String attributeName, String defaultValue)
    Returns a string attribute value in the map, returning the default value if no value was found.
    int
     
    protected void
    initAttributes(Map<String,V> attributes)
    Initializes this attribute map.
    boolean
    Is this attribute map empty with a size of 0?
    put(String attributeName, V attributeValue)
    Put the attribute into this map.
    putAll(AttributeMap<? extends V> attributes)
    Put all the attributes into this map.
    remove(String attributeName)
    Remove an attribute from this map.
    removeAll(MutableAttributeMap<? extends V> attributes)
    Remove all attributes in the map provided from this map.
    replaceWith(AttributeMap<? extends V> attributes)
    Replace the contents of this attribute map with the contents of the provided collection.
    int
    Returns the size of this map.
     
    union(AttributeMap<? extends V> attributes)
    Returns a new attribute map containing the union of this map with the provided map.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LocalAttributeMap

      public LocalAttributeMap()
      Creates a new attribute map, initially empty.
    • LocalAttributeMap

      public LocalAttributeMap(int size, int loadFactor)
      Creates a new attribute map, initially empty.
      Parameters:
      size - the initial size
      loadFactor - the load factor
    • LocalAttributeMap

      public LocalAttributeMap(String attributeName, V attributeValue)
      Creates a new attribute map with a single entry.
    • LocalAttributeMap

      public LocalAttributeMap(Map<String,V> map)
      Creates a new attribute map wrapping the specified map.
  • Method Details

    • asMap

      public Map<String,V> asMap()
      Description copied from interface: MapAdaptable
      Returns this object's contents as a Map. The returned map may or may not be modifiable depending on this implementation.

      Warning: this operation may be called frequently; if so care should be taken so that the map contents (if calculated) be cached as appropriate.

      Specified by:
      asMap in interface MapAdaptable<String,V>
      Returns:
      the object's contents as a map
    • size

      public int size()
      Description copied from interface: AttributeMap
      Returns the size of this map.
      Specified by:
      size in interface AttributeMap<V>
      Returns:
      the number of entries in the map
    • get

      public V get(String attributeName)
      Description copied from interface: AttributeMap
      Get an attribute value out of this map, returning null if not found.
      Specified by:
      get in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the attribute value
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: AttributeMap
      Is this attribute map empty with a size of 0?
      Specified by:
      isEmpty in interface AttributeMap<V>
      Returns:
      true if empty, false if not
    • contains

      public boolean contains(String attributeName)
      Description copied from interface: AttributeMap
      Does the attribute with the provided name exist in this map?
      Specified by:
      contains in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      true if so, false otherwise
    • contains

      public boolean contains(String attributeName, Class<? extends V> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Does the attribute with the provided name exist in this map and is its value of the specified required type?
      Specified by:
      contains in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      requiredType - the required class of the attribute value
      Returns:
      true if so, false otherwise
      Throws:
      IllegalArgumentException - when the value is not of the required type
    • get

      public V get(String attributeName, V defaultValue)
      Description copied from interface: AttributeMap
      Get an attribute value, returning the default value if no value is found.
      Specified by:
      get in interface AttributeMap<V>
      Parameters:
      attributeName - the name of the attribute
      defaultValue - the default value
      Returns:
      the attribute value, falling back to the default if no such attribute exists
    • get

      public <T extends V> T get(String attributeName, Class<T> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Get an attribute value, asserting the value is of the required type.
      Specified by:
      get in interface AttributeMap<V>
      Parameters:
      attributeName - the name of the attribute
      requiredType - the required type of the attribute value
      Returns:
      the attribute value, or null if not found
      Throws:
      IllegalArgumentException - when the value is not of the required type
    • get

      public <T extends V> T get(String attributeName, Class<T> requiredType, T defaultValue) throws IllegalStateException
      Description copied from interface: AttributeMap
      Get an attribute value, asserting the value is of the required type and returning the default value if not found.
      Specified by:
      get in interface AttributeMap<V>
      Parameters:
      attributeName - the name of the attribute
      requiredType - the value required type
      defaultValue - the default value
      Returns:
      the attribute value, or the default if not found
      Throws:
      IllegalStateException
    • getRequired

      public V getRequired(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Get the value of a required attribute, throwing an exception of no attribute is found.
      Specified by:
      getRequired in interface AttributeMap<V>
      Parameters:
      attributeName - the name of the attribute
      Returns:
      the attribute value
      Throws:
      IllegalArgumentException - when the attribute is not found
    • getRequired

      public <T extends V> T getRequired(String attributeName, Class<T> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Get the value of a required attribute and make sure it is of the required type.
      Specified by:
      getRequired in interface AttributeMap<V>
      Parameters:
      attributeName - name of the attribute to get
      requiredType - the required type of the attribute value
      Returns:
      the attribute value
      Throws:
      IllegalArgumentException - when the attribute is not found or not of the required type
    • getString

      public String getString(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a string attribute value in the map, returning null if no value was found.
      Specified by:
      getString in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the string attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a string
    • getString

      public String getString(String attributeName, String defaultValue) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a string attribute value in the map, returning the default value if no value was found.
      Specified by:
      getString in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      defaultValue - the default
      Returns:
      the string attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a string
    • getRequiredString

      public String getRequiredString(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a string attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
      Specified by:
      getRequiredString in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the string attribute value
      Throws:
      IllegalArgumentException - if the attribute is not present or present but not a string
    • getCollection

      public Collection<V> getCollection(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a collection attribute value in the map.
      Specified by:
      getCollection in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the collection attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a collection
    • getCollection

      public <T extends Collection<V>> T getCollection(String attributeName, Class<T> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a collection attribute value in the map and make sure it is of the required type.
      Specified by:
      getCollection in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      requiredType - the required type of the attribute value
      Returns:
      the collection attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a collection of the required type
    • getRequiredCollection

      public Collection<V> getRequiredCollection(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a collection attribute value in the map, throwing an exception if the attribute is not present or not a collection.
      Specified by:
      getRequiredCollection in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the collection attribute value
      Throws:
      IllegalArgumentException - if the attribute is not present or is present but not a collection
    • getRequiredCollection

      public <T extends Collection<V>> T getRequiredCollection(String attributeName, Class<T> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a collection attribute value in the map, throwing an exception if the attribute is not present or not a collection of the required type.
      Specified by:
      getRequiredCollection in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      requiredType - the required collection type
      Returns:
      the collection attribute value
      Throws:
      IllegalArgumentException - if the attribute is not present or is present but not a collection of the required type
    • getArray

      public <T extends V> T[] getArray(String attributeName, Class<? extends T[]> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns an array attribute value in the map and makes sure it is of the required type.
      Specified by:
      getArray in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      requiredType - the required type of the attribute value
      Returns:
      the array attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not an array of the required type
    • getRequiredArray

      public <T extends V> T[] getRequiredArray(String attributeName, Class<? extends T[]> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns an array attribute value in the map, throwing an exception if the attribute is not present or not an array of the required type.
      Specified by:
      getRequiredArray in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      requiredType - the required array type
      Returns:
      the collection attribute value
      Throws:
      IllegalArgumentException - if the attribute is not present or is present but not a array of the required type
    • getNumber

      public <T extends Number> T getNumber(String attributeName, Class<T> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a number attribute value in the map that is of the specified type, returning null if no value was found.
      Specified by:
      getNumber in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      requiredType - the required number type
      Returns:
      the number attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a number of the required type
    • getNumber

      public <T extends Number> T getNumber(String attributeName, Class<T> requiredType, T defaultValue) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a number attribute value in the map of the specified type, returning the default value if no value was found.
      Specified by:
      getNumber in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      defaultValue - the default
      Returns:
      the number attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a number of the required type
    • getRequiredNumber

      public <T extends Number> T getRequiredNumber(String attributeName, Class<T> requiredType) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a number attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
      Specified by:
      getRequiredNumber in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the number attribute value
      Throws:
      IllegalArgumentException - if the attribute is not present or present but not a number of the required type
    • getInteger

      public Integer getInteger(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns an integer attribute value in the map, returning null if no value was found.
      Specified by:
      getInteger in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the integer attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not an integer
    • getInteger

      public Integer getInteger(String attributeName, Integer defaultValue) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns an integer attribute value in the map, returning the default value if no value was found.
      Specified by:
      getInteger in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      defaultValue - the default
      Returns:
      the integer attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not an integer
    • getRequiredInteger

      public Integer getRequiredInteger(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns an integer attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
      Specified by:
      getRequiredInteger in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the integer attribute value
      Throws:
      IllegalArgumentException - if the attribute is not present or present but not an integer
    • getLong

      public Long getLong(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a long attribute value in the map, returning null if no value was found.
      Specified by:
      getLong in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the long attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a long
    • getLong

      public Long getLong(String attributeName, Long defaultValue) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a long attribute value in the map, returning the default value if no value was found.
      Specified by:
      getLong in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      defaultValue - the default
      Returns:
      the long attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a long
    • getRequiredLong

      public Long getRequiredLong(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a long attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
      Specified by:
      getRequiredLong in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the long attribute value
      Throws:
      IllegalArgumentException - if the attribute is not present or present but not a long
    • getBoolean

      public Boolean getBoolean(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a boolean attribute value in the map, returning null if no value was found.
      Specified by:
      getBoolean in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the long attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a boolean
    • getBoolean

      public Boolean getBoolean(String attributeName, Boolean defaultValue) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a boolean attribute value in the map, returning the default value if no value was found.
      Specified by:
      getBoolean in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      defaultValue - the default
      Returns:
      the boolean attribute value
      Throws:
      IllegalArgumentException - if the attribute is present but not a boolean
    • getRequiredBoolean

      public Boolean getRequiredBoolean(String attributeName) throws IllegalArgumentException
      Description copied from interface: AttributeMap
      Returns a boolean attribute value in the map, throwing an exception if the attribute is not present and of the correct type.
      Specified by:
      getRequiredBoolean in interface AttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the boolean attribute value
      Throws:
      IllegalArgumentException - if the attribute is not present or present but is not a boolean
    • union

      public AttributeMap<V> union(AttributeMap<? extends V> attributes)
      Description copied from interface: AttributeMap
      Returns a new attribute map containing the union of this map with the provided map.
      Specified by:
      union in interface AttributeMap<V>
      Parameters:
      attributes - the map to combine with this map
      Returns:
      a new, combined map
    • put

      public V put(String attributeName, V attributeValue)
      Description copied from interface: MutableAttributeMap
      Put the attribute into this map.

      If the attribute value is an AttributeMapBindingListener this map will publish binding events such as on "bind" and "unbind" if supported.

      Note: not all MutableAttributeMap implementations support this.

      Specified by:
      put in interface MutableAttributeMap<V>
      Parameters:
      attributeName - the attribute name
      attributeValue - the attribute value
      Returns:
      the previous value of the attribute, or null of there was no previous value
    • putAll

      public MutableAttributeMap<V> putAll(AttributeMap<? extends V> attributes)
      Description copied from interface: MutableAttributeMap
      Put all the attributes into this map.
      Specified by:
      putAll in interface MutableAttributeMap<V>
      Parameters:
      attributes - the attributes to put into this map
      Returns:
      this, to support call chaining
    • removeAll

      public MutableAttributeMap<V> removeAll(MutableAttributeMap<? extends V> attributes)
      Description copied from interface: MutableAttributeMap
      Remove all attributes in the map provided from this map.
      Specified by:
      removeAll in interface MutableAttributeMap<V>
      Parameters:
      attributes - the attributes to remove from this map
      Returns:
      this, to support call chaining
    • remove

      public Object remove(String attributeName)
      Description copied from interface: MutableAttributeMap
      Remove an attribute from this map.
      Specified by:
      remove in interface MutableAttributeMap<V>
      Parameters:
      attributeName - the name of the attribute to remove
      Returns:
      previous value associated with specified attribute name, or null if there was no mapping for the name
    • extract

      public Object extract(String attributeName)
      Description copied from interface: MutableAttributeMap
      Extract an attribute from this map, getting it and removing it in a single operation.
      Specified by:
      extract in interface MutableAttributeMap<V>
      Parameters:
      attributeName - the attribute name
      Returns:
      the value of the attribute, or null of there was no value
    • clear

      Description copied from interface: MutableAttributeMap
      Remove all attributes in this map.
      Specified by:
      clear in interface MutableAttributeMap<V>
      Returns:
      this, to support call chaining
      Throws:
      UnsupportedOperationException
    • replaceWith

      public MutableAttributeMap<V> replaceWith(AttributeMap<? extends V> attributes) throws UnsupportedOperationException
      Description copied from interface: MutableAttributeMap
      Replace the contents of this attribute map with the contents of the provided collection.
      Specified by:
      replaceWith in interface MutableAttributeMap<V>
      Parameters:
      attributes - the attribute collection
      Returns:
      this, to support call chaining
      Throws:
      UnsupportedOperationException
    • initAttributes

      protected void initAttributes(Map<String,V> attributes)
      Initializes this attribute map.
      Parameters:
      attributes - the attributes
    • getMapInternal

      protected Map<String,V> getMapInternal()
      Returns the wrapped, modifiable map implementation.
    • createTargetMap

      protected Map<String,V> createTargetMap()
      Factory method that returns the target map storing the data in this attribute map.
      Returns:
      the target map
    • createTargetMap

      protected Map<String,V> createTargetMap(int size, int loadFactor)
      Factory method that returns the target map storing the data in this attribute map.
      Parameters:
      size - the initial size of the map
      loadFactor - the load factor
      Returns:
      the target map
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object