Package org.jibx.util
Class ChainedMap
- java.lang.Object
-
- org.jibx.util.ChainedMap
-
- All Implemented Interfaces:
java.util.Map
public class ChainedMap extends java.lang.Object implements java.util.MapPartial implementation ofMapwhich 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 Summary
Fields Modifier and Type Field Description private java.util.Mapm_defaultsDefault values map.private java.util.Mapm_overridesOverride values map.
-
Constructor Summary
Constructors Constructor Description ChainedMap(java.util.Map defaults)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear all override key-value pairs.booleancontainsKey(java.lang.Object key)Check if a key has a defined value.booleancontainsValue(java.lang.Object value)Check if a value is present.java.util.SetentrySet()Get the set of entries.java.lang.Objectget(java.lang.Object key)Get value for key.booleanisEmpty()Check if no overrides are defined.java.util.SetkeySet()Get the set of keys.java.lang.Objectput(java.lang.Object key, java.lang.Object value)Set an override value.voidputAll(java.util.Map map)Add all key-value pairs from another map into the overrides map.java.lang.Objectremove(java.lang.Object key)Remove a key-value pair.intsize()Get the number of entries in the map.java.util.Collectionvalues()Get the values.
-
-
-
Method Detail
-
clear
public void clear()
Clear all override key-value pairs. This only effects the overrides, not the defaults.- Specified by:
clearin interfacejava.util.Map
-
containsKey
public boolean containsKey(java.lang.Object key)
Check if a key has a defined value. This will returntrueif 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:
containsKeyin interfacejava.util.Map- Parameters:
key-- Returns:
trueif key defined,falseif not
-
containsValue
public boolean containsValue(java.lang.Object value)
Check if a value is present. This only checks for the value in the overrides map.- Specified by:
containsValuein interfacejava.util.Map- Parameters:
value-- Returns:
trueif value present as an override,falseif not
-
entrySet
public java.util.Set entrySet()
Get the set of entries. This only returns the entries in the overrides map.- Specified by:
entrySetin interfacejava.util.Map- Returns:
- override entries
-
get
public java.lang.Object get(java.lang.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:
getin interfacejava.util.Map- Parameters:
key-- Returns:
- value (
nullif key not present)
-
isEmpty
public boolean isEmpty()
Check if no overrides are defined.- Specified by:
isEmptyin interfacejava.util.Map- Returns:
trueif no overrides,falseif any present
-
keySet
public java.util.Set keySet()
Get the set of keys. This only returns the keys in the overrides map.- Specified by:
keySetin interfacejava.util.Map- Returns:
- keys
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)Set an override value. This just adds the key-value pair to the override map.- Specified by:
putin interfacejava.util.Map- Parameters:
key-value-- Returns:
- previous value for key (from default map, if not present in overrides)
-
putAll
public void putAll(java.util.Map map)
Add all key-value pairs from another map into the overrides map.- Specified by:
putAllin interfacejava.util.Map- Parameters:
map-
-
remove
public java.lang.Object remove(java.lang.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:
removein interfacejava.util.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:
sizein interfacejava.util.Map- Returns:
- entry count
-
values
public java.util.Collection values()
Get the values. This returns only the values in the overrides map.- Specified by:
valuesin interfacejava.util.Map- Returns:
- values
-
-