Package pascal.taie.util.collection
Interface TwoKeyMap<K1,K2,V>
- Type Parameters:
K1
- type of first keys in this mapK2
- type of second keys in this mapV
- type of values in this map
- All Known Implementing Classes:
AbstractTwoKeyMap
,MapMapTwoKeyMap
public interface TwoKeyMap<K1,K2,V>
A collection that maps two-key pairs to values.
You can visualize the contents of a two-key map either as a map from keys
to second-level maps as values:
- k1 -> { k2 -> v1, k3 -> v2 }
- k2 -> { k4 -> v1 }
... or as a single "flattened" collection of key1-key2-value triples:
- k1, k2 -> v1
- k1, k3 -> v2
- k2, k4 -> v1
Note that both null
keys and values are not permitted in this map.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final record
A map entry (key1-key2-value triple). -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all the mappings from this map.default V
computeIfAbsent
(K1 key1, K2 key2, BiFunction<K1, K2, V> mapper) If the specified key-pair is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unlessnull
.boolean
containsKey
(K1 key1) boolean
containsKey
(K1 key1, K2 key2) boolean
containsValue
(V value) Set<TwoKeyMap.Entry<K1,
K2, V>> entrySet()
default void
forEach
(TriConsumer<K1, K2, V> action) Performs the given action for all key1-key2-value triples contained in this map.getOrDefault
(K1 key1, Map<K2, V> defaultValue) default V
getOrDefault
(K1 key1, K2 key2, V defaultValue) boolean
isEmpty()
keySet()
Associates the specified value with the specified two-key pair in this map.void
Copies all the mappings from the specified map to second-level map associated withkey1
.void
Copies all the mappings from the specified two-key map to this map.Removes the mapping for a key-pair from this map if it is present.boolean
Removes all mappings withkey1
as the first key in this map.void
replaceALl
(TriFunction<? super K1, ? super K2, ? super V, ? extends V> function) Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.int
size()
values()
-
Method Details
-
containsKey
- Returns:
true
if this two-key map contains the mapping withkey1
as the first key andkey2
as the second key.
-
containsKey
- Returns:
true
if this two-key map contains at least one mapping withkey1
as the first key.
-
containsValue
- Returns:
true
if this two-key map contains at least one mapping withvalue
as the value. Note that this operation may be slow compared tocontainsKey(Object)
.
-
get
- Returns:
- the value to which the specified keys is mapped, or
null
if this map contains no mapping for the keys.
-
get
- Returns:
- an unmodifiable view of the second-level map for
key1
, ornull
if this map contains no mapping for the key.
-
put
Associates the specified value with the specified two-key pair in this map. If the map previously contained a mapping for the keys, the old value is replaced by the specified value.- Returns:
- the previous value associated with
key1
andkey2
, ornull
if there was no mapping for key2.
-
putAll
Copies all the mappings from the specified map to second-level map associated withkey1
. -
putAll
Copies all the mappings from the specified two-key map to this map. -
remove
Removes the mapping for a key-pair from this map if it is present.- Returns:
- the value to which this map previously associated the key pair,
or
null
if the map contained no mapping for the key pair.
-
removeAll
Removes all mappings withkey1
as the first key in this map.- Returns:
true
if the two-key map changed.
-
replaceALl
Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception. -
twoKeySet
- Returns:
- an unmodifiable view of all distinct two-key pairs
contained in this two-key map. Note that the result contains
a two-key pair if and only if this map maps that key pair to
a non-
null
value.
-
keySet
- Returns:
- an unmodifiable view of first keys of all mappings contained in this two-key map. Note that the result contains a key if and only if this map contains at least one mapping with the key as the first key.
-
values
Collection<V> values()- Returns:
- an unmodifiable view collection containing the value
from each key1-key2-value triples contained in this map, without
collapsing duplicates (so
values().size() == size()
).
-
entrySet
Set<TwoKeyMap.Entry<K1,K2, entrySet()V>> - Returns:
- an unmodifiable view of all key1-key2-value triples
contained in this two-key map, as
TwoKeyMap.Entry
instances.
-
forEach
Performs the given action for all key1-key2-value triples contained in this map. -
getOrDefault
- Returns:
- the k2-value map to which the specified key is mapped,
or
defaultValue
if this map contains no mapping for the key.
-
getOrDefault
- Returns:
- the value to which the specified key-pair is mapped,
or
defaultValue
if this map contains no mapping for the key-pair.
-
computeIfAbsent
If the specified key-pair is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unlessnull
.If the mapping function returns
null
, no mapping is recorded. If the mapping function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded.- Returns:
- the current (existing or computed) value associated with
the specified key, or
null
if the computed value isnull
.
-
clear
void clear()Removes all the mappings from this map. The map will be empty after this call returns. -
isEmpty
boolean isEmpty()- Returns:
true
if this map contains no key1-key2-value mappings.
-
size
int size()- Returns:
- the number of key1-key2-value mappings in this map.
-