Package org.jibx.util

Class ChainedMap

java.lang.Object
org.jibx.util.ChainedMap
All Implemented Interfaces:
Map

public class ChainedMap extends Object implements Map
Partial implementation of Map which provides a merged view of a defaults map with an overrides map. Although this can be used as a map for most purposes, methods which return live views of the keys or values in the map only take into account the overrides, not the defaults.
  • Field Details

    • m_defaults

      private final Map m_defaults
      Default values map.
    • m_overrides

      private final Map m_overrides
      Override values map.
  • Constructor Details

    • ChainedMap

      public ChainedMap(Map defaults)
      Constructor.
      Parameters:
      defaults - map providing defaults for keys not set directly
  • Method Details

    • clear

      public void clear()
      Clear all override key-value pairs. This only effects the overrides, not the defaults.
      Specified by:
      clear in interface Map
    • containsKey

      public boolean containsKey(Object key)
      Check if a key has a defined value. This will return true if the key is present in the overrides map with a non-null value, or if the key is not present in the overrides map but is present in the defaults map.
      Specified by:
      containsKey in interface Map
      Parameters:
      key -
      Returns:
      true if key defined, false if not
    • containsValue

      public boolean containsValue(Object value)
      Check if a value is present. This only checks for the value in the overrides map.
      Specified by:
      containsValue in interface Map
      Parameters:
      value -
      Returns:
      true if value present as an override, false if not
    • entrySet

      public Set entrySet()
      Get the set of entries. This only returns the entries in the overrides map.
      Specified by:
      entrySet in interface Map
      Returns:
      override entries
    • get

      public Object get(Object key)
      Get value for key. If the key is present in the overrides map, the value from that map is returned; otherwise, the value for the key in the defaults map is returned.
      Specified by:
      get in interface Map
      Parameters:
      key -
      Returns:
      value (null if key not present)
    • isEmpty

      public boolean isEmpty()
      Check if no overrides are defined.
      Specified by:
      isEmpty in interface Map
      Returns:
      true if no overrides, false if any present
    • keySet

      public Set keySet()
      Get the set of keys. This only returns the keys in the overrides map.
      Specified by:
      keySet in interface Map
      Returns:
      keys
    • put

      public Object put(Object key, Object value)
      Set an override value. This just adds the key-value pair to the override map.
      Specified by:
      put in interface Map
      Parameters:
      key -
      value -
      Returns:
      previous value for key (from default map, if not present in overrides)
    • putAll

      public void putAll(Map map)
      Add all key-value pairs from another map into the overrides map.
      Specified by:
      putAll in interface Map
      Parameters:
      map -
    • remove

      public Object remove(Object key)
      Remove a key-value pair. If the key was previously present in the overrides map it is simply removed from that map. If it was not present in the overrides map but is present in the defaults map, a null entry is added to the overrides map for that key.
      Specified by:
      remove in interface Map
      Parameters:
      key -
      Returns:
      previous value for key
    • size

      public int size()
      Get the number of entries in the map. This returns the entry count for the overrides map only.
      Specified by:
      size in interface Map
      Returns:
      entry count
    • values

      public Collection values()
      Get the values. This returns only the values in the overrides map.
      Specified by:
      values in interface Map
      Returns:
      values