Package com.tangosol.util
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ChainedMap.EntrySet
A set of entries backed by this map.-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected Map
m_mapFirst
The first map.protected Map
m_mapSecond
The second map.protected ChainedMap.EntrySet
m_setEntries
The entry set.
-
Constructor Summary
Constructors Constructor Description ChainedMap(Map mapFirst, Map mapSecond)
Construct a ChainedMap out of two maps.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(Object oKey)
Returns true if this map contains a mapping for the specified key.Set
entrySet()
Returns a set view of the mappings contained in this map.Object
get(Object oKey)
Returns the value to which this map maps the specified key.Map
getFirstMap()
Get the first (front) map.Map
getSecondMap()
Get the second (back) map.protected ChainedMap.EntrySet
instantiateEntrySet()
(Factory pattern) Instantiate an Entry Set or subclass thereof.Object
put(Object oKey, Object oValue)
Associates the specified value with the specified key in this map.Object
remove(Object oKey)
Removes the mapping for this key from this map if present.int
size()
Returns the number of key-value mappings in this map.-
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
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.
-
-
Method Detail
-
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 interfaceMap
- Overrides:
size
in classAbstractMap
- 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 interfaceMap
- Overrides:
containsKey
in classAbstractMap
- 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 interfaceMap
- Overrides:
get
in classAbstractMap
- 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 interfaceMap
- Overrides:
put
in classAbstractMap
- Parameters:
oKey
- key with which the specified value is to be associatedoValue
- 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 interfaceMap
- Overrides:
remove
in classAbstractMap
- 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 interfaceMap
- Specified by:
entrySet
in classAbstractMap
- 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
-
-