Package com.groiss.ds
Class TwoLevelMap<K1,K2,V>
java.lang.Object
com.groiss.ds.TwoLevelMap<K1,K2,V>
HashMap based two-level Map.
A value can be associated with a "key path" which is an ordered list of two keys.
It can be also be determined if something has been associated with the first component
of a key path irrespective of the concrete second component of the key path.
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionConstructs an emptyTwoLevelMap
.TwoLevelMap
(String name) Constructs an emptyTwoLevelMap
with the specified name.TwoLevelMap
(String name, int initialCapacity) Constructs an emptyTwoLevelMap
with the specified name and initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Pair<K1, K2> p) Returnstrue
if this map contains a mapping for the specified key path designated by the specified Pairboolean
containsKey
(Object key1) Returnstrue
if this map contains a mapping for the specified key path component.boolean
containsKey
(K1 key1, K2 key2) Returnstrue
if this map contains a mapping for the specified key path.boolean
containsValue
(Object value) entrySet()
Deprecated.Returns the value to which the specified key path designated by the Pair is mapped in this map, ornull
if the map contains no mapping for this key path.Returns the Map of values to which the specified key path component is mapped in this map, ornull
if the map contains no mapping for this key path component.Returns the value to which the specified key path is mapped in this map, ornull
if the map contains no mapping for this key path.boolean
isEmpty()
keySet()
Associates the specified value with the key path designated by the Pair in this map.Associates the specified value with the specified key path key1 / key2 in this map.void
Removes the mapping for the key path designated by the specified Pair from this map if present.Removes the mapping for this key path component from this map if present.removeByKeys
(Object key1, Object key2) Removes the mapping for this key path from this map if present.int
size()
Returns the number of first level key path mappings in this map.toString()
Collection<Map<K2,
V>> values()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
TwoLevelMap
public TwoLevelMap()Constructs an emptyTwoLevelMap
. -
TwoLevelMap
Constructs an emptyTwoLevelMap
with the specified name.- Parameters:
name
- the name of this map.
-
TwoLevelMap
Constructs an emptyTwoLevelMap
with the specified name and initial capacity.- Parameters:
name
- the name of this map.initialCapacity
- the initial capacity.
-
-
Method Details
-
clear
public void clear() -
containsKey
Returnstrue
if this map contains a mapping for the specified key path.- Parameters:
key1
- The first part of the key path whose presence in this map is to be testedkey2
- The second part of the key path whose presence in this map is to be tested- Returns:
true
if this map contains a mapping for the specified key path.
-
containsKey
Returnstrue
if this map contains a mapping for the specified key path component.- Specified by:
containsKey
in interfaceMap<K1,
K2> - Parameters:
key1
- The first part of the key path whose presence in this map is to be tested- Returns:
true
if this map contains a mapping for the specified key path component.
-
containsKey
Returnstrue
if this map contains a mapping for the specified key path designated by the specified Pair- Parameters:
p
- the Pair designating the key path p.first designated the first path component, p.second designates the second path component- Returns:
true
if this map contains a mapping for the specified key path.
-
containsValue
- Specified by:
containsValue
in interfaceMap<K1,
K2>
-
entrySet
-
firstKeySet
Deprecated.since 8.0; usekeySet()
- Returns:
- the first level keyset
-
get
Returns the value to which the specified key path is mapped in this map, ornull
if the map contains no mapping for this key path. A return value ofnull
does not necessarily indicate that the map contains no mapping for the key path ; it is also possible that the map explicitly maps the key path tonull
. ThecontainsKey
method may be used to distinguish these two cases.- Parameters:
key1
- the first component of the key path whose associated map is to be returned.key2
- the second component of the key path whose associated map is to be returned.- Returns:
- the value to which this map maps the specified key path, or
null
if the map contains no mapping for this key path. - See Also:
-
get
Returns the Map of values to which the specified key path component is mapped in this map, ornull
if the map contains no mapping for this key path component. A return value ofnull
does not necessarily indicate that the map contains no mapping for the key path component; it is also possible that the map explicitly maps the key path component tonull
. ThecontainsKey
method may be used to distinguish these two cases. -
get
Returns the value to which the specified key path designated by the Pair is mapped in this map, ornull
if the map contains no mapping for this key path. A return value ofnull
does not necessarily indicate that the map contains no mapping for the key path ; it is also possible that the map explicitly maps the key path tonull
. ThecontainsKey
method may be used to distinguish these two cases.- Parameters:
p
- the Pair designating the key path p.first designated the first path component, p.second designates the second path component- Returns:
- the value to which this map maps the specified key path, or
null
if the map contains no mapping for this key path. - See Also:
-
isEmpty
public boolean isEmpty() -
keySet
-
put
Associates the specified value with the specified key path key1 / key2 in this map. If the map previously contained a mapping for this key path, the old value is replaced.- Parameters:
key1
- the first component of the key path with which the specified value is to be associated.key2
- the second component of the key path with which the specified value is to be associated.value
- value to be associated with the specified key path.- Returns:
- previous value associated with specified key path, or
null
if there was no mapping for key path. Anull
return can also indicate that the HashMap previously associatednull
with the specified key.
-
put
-
put
Associates the specified value with the key path designated by the Pair in this map. If the map previously contained a mapping for this key path, the old value is replaced.- Parameters:
p
- the Pair designating the key path p.first() designated the first path component, p.second() designates the second path componentvalue
- value to be associated with the specified key path.- Returns:
- previous value associated with specified key path, or
null
if there was no mapping for key path. Anull
return can also indicate that the HashMap previously associatednull
with the specified key.
-
putAll
-
remove
Removes the mapping for this key path component from this map if present.- Specified by:
remove
in interfaceMap<K1,
K2> - Parameters:
key1
- key path component whose mapping is to be removed from the map.- Returns:
- previous Map associated with specified key path component , or
null
if there was no mapping for key1. Anull
return can also indicate that the map previously associatednull
with the specified key.
-
removeByKeys
Removes the mapping for this key path from this map if present.- Parameters:
key1
- the first component of the key path whose mapping is to be removed from the map.key2
- the second component of the key path whose mapping is to be removed from the map.- Returns:
- previous value associated with specified key path, or
null
if there was no mapping for the key path. Anull
return can also indicate that the value previously associatednull
with the specified key path. - Since:
- ep9.0 (February 2015); formerly this method has been named
remove
. Renamed because of clash with new method in Java 8.
-
remove
Removes the mapping for the key path designated by the specified Pair from this map if present.- Parameters:
p
- the Pair designating the key path p.first designated the first path component, p.second designates the second path component- Returns:
- previous value associated with specified key path, or
null
if there was no mapping for the key path. Anull
return can also indicate that the value previously associatednull
with the specified key path.
-
size
public int size()Returns the number of first level key path mappings in this map. -
toString
-
values
-
keySet()