Package org.jibx.util
Class ChainedMap
java.lang.Object
org.jibx.util.ChainedMap
- All Implemented Interfaces:
Map
Partial implementation of
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.-
Nested Class Summary
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear all override key-value pairs.boolean
containsKey
(Object key) Check if a key has a defined value.boolean
containsValue
(Object value) Check if a value is present.entrySet()
Get the set of entries.Get value for key.boolean
isEmpty()
Check if no overrides are defined.keySet()
Get the set of keys.Set an override value.void
Add all key-value pairs from another map into the overrides map.Remove a key-value pair.int
size()
Get the number of entries in the map.values()
Get the values.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
m_defaults
Default values map. -
m_overrides
Override values map.
-
-
Constructor Details
-
ChainedMap
Constructor.- Parameters:
defaults
- map providing defaults for keys not set directly
-
-
Method Details
-
clear
public void clear()Clear all override key-value pairs. This only effects the overrides, not the defaults. -
containsKey
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 interfaceMap
- Parameters:
key
-- Returns:
true
if key defined,false
if not
-
containsValue
Check if a value is present. This only checks for the value in the overrides map.- Specified by:
containsValue
in interfaceMap
- Parameters:
value
-- Returns:
true
if value present as an override,false
if not
-
entrySet
Get the set of entries. This only returns the entries in the overrides map. -
get
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. -
isEmpty
public boolean isEmpty()Check if no overrides are defined. -
keySet
Get the set of keys. This only returns the keys in the overrides map. -
put
Set an override value. This just adds the key-value pair to the override map. -
putAll
Add all key-value pairs from another map into the overrides map. -
remove
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. -
size
public int size()Get the number of entries in the map. This returns the entry count for the overrides map only. -
values
Get the values. This returns only the values in the overrides map.
-