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.Map
Partial implementation ofMap
which 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.Map
m_defaults
Default values map.private java.util.Map
m_overrides
Override 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 void
clear()
Clear all override key-value pairs.boolean
containsKey(java.lang.Object key)
Check if a key has a defined value.boolean
containsValue(java.lang.Object value)
Check if a value is present.java.util.Set
entrySet()
Get the set of entries.java.lang.Object
get(java.lang.Object key)
Get value for key.boolean
isEmpty()
Check if no overrides are defined.java.util.Set
keySet()
Get the set of keys.java.lang.Object
put(java.lang.Object key, java.lang.Object value)
Set an override value.void
putAll(java.util.Map map)
Add all key-value pairs from another map into the overrides map.java.lang.Object
remove(java.lang.Object key)
Remove a key-value pair.int
size()
Get the number of entries in the map.java.util.Collection
values()
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:
clear
in interfacejava.util.Map
-
containsKey
public boolean containsKey(java.lang.Object key)
Check if a key has a defined value. This will returntrue
if 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:
containsKey
in interfacejava.util.Map
- Parameters:
key
-- Returns:
true
if key defined,false
if 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:
containsValue
in interfacejava.util.Map
- Parameters:
value
-- Returns:
true
if value present as an override,false
if not
-
entrySet
public java.util.Set entrySet()
Get the set of entries. This only returns the entries in the overrides map.- Specified by:
entrySet
in 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:
get
in interfacejava.util.Map
- Parameters:
key
-- Returns:
- value (
null
if key not present)
-
isEmpty
public boolean isEmpty()
Check if no overrides are defined.- Specified by:
isEmpty
in interfacejava.util.Map
- Returns:
true
if no overrides,false
if any present
-
keySet
public java.util.Set keySet()
Get the set of keys. This only returns the keys in the overrides map.- Specified by:
keySet
in 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:
put
in 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:
putAll
in 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:
remove
in 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:
size
in 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:
values
in interfacejava.util.Map
- Returns:
- values
-
-