Class ChainedMap

java.lang.Object
java.util.AbstractMap
com.tangosol.util.ChainedMap
All Implemented Interfaces:
Serializable, Map

public class ChainedMap extends AbstractMap implements Serializable
Chains two maps into one virtual map.

The contents of the first map take precedence over the contents in the second map. If there are already entries in the two maps when this map is constructed, then the keys in the second map that are also in the first map will be removed from the second map.

Since:
Coherence 2.4
Author:
cp 2004.03.24
See Also:
  • Field Details

    • m_mapFirst

      protected Map m_mapFirst
      The first map.
    • m_mapSecond

      protected Map m_mapSecond
      The second map.
    • m_setEntries

      protected transient ChainedMap.EntrySet m_setEntries
      The entry set.
  • Constructor Details

    • ChainedMap

      public ChainedMap(Map mapFirst, Map mapSecond)
      Construct a ChainedMap out of two maps.
      Parameters:
      mapFirst - the first map whose mappings are to be placed in this map.
      mapSecond - the second map whose mappings are to be placed in this map.
  • Method Details

    • getFirstMap

      public Map getFirstMap()
      Get the first (front) map.

      Note: direct modifications of the returned map may cause an unpredictable behavior of the ChainedMap.

      Returns:
      the first Map
    • getSecondMap

      public Map getSecondMap()
      Get the second (back) map.

      Note: direct modifications of the returned map may cause an unpredictable behavior of the ChainedMap.

      Returns:
      the second Map
    • size

      public int size()
      Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
      Specified by:
      size in interface Map
      Overrides:
      size in class AbstractMap
      Returns:
      the number of key-value mappings in this map
    • containsKey

      public boolean containsKey(Object oKey)
      Returns true if this map contains a mapping for the specified key.
      Specified by:
      containsKey in interface Map
      Overrides:
      containsKey in class AbstractMap
      Parameters:
      oKey - key whose presence in this map is to be tested
      Returns:
      true if this map contains a mapping for the specified key
    • get

      public Object get(Object oKey)
      Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.
      Specified by:
      get in interface Map
      Overrides:
      get in class AbstractMap
      Parameters:
      oKey - key whose associated value is to be returned
      Returns:
      the value to which this map maps the specified key, or null if the map contains no mapping for this key
    • put

      public Object put(Object oKey, Object oValue)
      Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.
      Specified by:
      put in interface Map
      Overrides:
      put in class AbstractMap
      Parameters:
      oKey - key with which the specified value is to be associated
      oValue - value to be associated with the specified key
      Returns:
      previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values
    • remove

      public Object remove(Object oKey)
      Removes the mapping for this key from this map if present.
      Specified by:
      remove in interface Map
      Overrides:
      remove in class AbstractMap
      Parameters:
      oKey - key whose mapping is to be removed from the map
      Returns:
      previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values
    • entrySet

      public Set entrySet()
      Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
      Specified by:
      entrySet in interface Map
      Specified by:
      entrySet in class AbstractMap
      Returns:
      a set view of the mappings contained in this map.
    • instantiateEntrySet

      protected ChainedMap.EntrySet instantiateEntrySet()
      (Factory pattern) Instantiate an Entry Set or subclass thereof. This method permits inheriting classes to easily override the implementation of the EntrySet object.
      Returns:
      an instance of EntrySet