public class ChainedMap
extends java.lang.Object
implements java.util.Map
Map
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.Modifier and Type | Field and Description |
---|---|
private java.util.Map |
m_defaults
Default values map.
|
private java.util.Map |
m_overrides
Override values map.
|
Constructor and Description |
---|
ChainedMap(java.util.Map defaults)
Constructor.
|
Modifier and Type | Method and 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.
|
private final java.util.Map m_defaults
private final java.util.Map m_overrides
public ChainedMap(java.util.Map defaults)
defaults
- map providing defaults for keys not set directlypublic void clear()
clear
in interface java.util.Map
public boolean containsKey(java.lang.Object key)
true
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.containsKey
in interface java.util.Map
key
- true
if key defined, false
if notpublic boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
value
- true
if value present as an override, false
if notpublic java.util.Set entrySet()
entrySet
in interface java.util.Map
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
key
- null
if key not present)public boolean isEmpty()
isEmpty
in interface java.util.Map
true
if no overrides, false
if any presentpublic java.util.Set keySet()
keySet
in interface java.util.Map
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
key
- value
- public void putAll(java.util.Map map)
putAll
in interface java.util.Map
map
- public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
key
- public int size()
size
in interface java.util.Map
public java.util.Collection values()
values
in interface java.util.Map