Package com.tangosol.util
Class ChainedMap
java.lang.Object
java.util.AbstractMap
com.tangosol.util.ChainedMap
- All Implemented Interfaces:
Serializable
,Map
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
Modifier and TypeFieldDescriptionprotected Map
The first map.protected Map
The second map.protected ChainedMap.EntrySet
The entry set. -
Constructor Summary
ConstructorDescriptionChainedMap
(Map mapFirst, Map mapSecond) Construct a ChainedMap out of two maps. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(Object oKey) Returns true if this map contains a mapping for the specified key.entrySet()
Returns a set view of the mappings contained in this map.Returns the value to which this map maps the specified key.Get the first (front) map.Get the second (back) map.protected ChainedMap.EntrySet
(Factory pattern) Instantiate an Entry Set or subclass thereof.Associates the specified value with the specified key in this map.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 Details
-
m_mapFirst
The first map. -
m_mapSecond
The second map. -
m_setEntries
The entry set.
-
-
Constructor Details
-
ChainedMap
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
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
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
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
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
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
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
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
(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
-