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 classChainedMap.EntrySetA 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 Mapm_mapFirstThe first map.protected Mapm_mapSecondThe second map.protected ChainedMap.EntrySetm_setEntriesThe 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 booleancontainsKey(Object oKey)Returns true if this map contains a mapping for the specified key.SetentrySet()Returns a set view of the mappings contained in this map.Objectget(Object oKey)Returns the value to which this map maps the specified key.MapgetFirstMap()Get the first (front) map.MapgetSecondMap()Get the second (back) map.protected ChainedMap.EntrySetinstantiateEntrySet()(Factory pattern) Instantiate an Entry Set or subclass thereof.Objectput(Object oKey, Object oValue)Associates the specified value with the specified key in this map.Objectremove(Object oKey)Removes the mapping for this key from this map if present.intsize()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:
sizein interfaceMap- Overrides:
sizein 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:
containsKeyin interfaceMap- Overrides:
containsKeyin 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:
getin interfaceMap- Overrides:
getin 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:
putin interfaceMap- Overrides:
putin 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:
removein interfaceMap- Overrides:
removein 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:
entrySetin interfaceMap- Specified by:
entrySetin 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
-
-