Package pascal.taie.util.collection
Interface MultiMap<K,V>
- Type Parameters:
K
- type of the keys in this mapV
- type of the values in this map
- All Known Implementing Classes:
AbstractMultiMap
,MapSetMultiMap
public interface MultiMap<K,V>
A collection that maps keys to values, similar to
Map
,
but in which each key may be associated with multiple values.
The values associated with the same key contain no duplicates.
You can visualize the contents of a multimap either as a map from keys
to nonempty collections of values:
- k1 -> [v1]
- k2 -> [v2, v3]
- k3 -> [v2, v5]
... or as a single "flattened" collection of key-value pairs:
- k1 -> v1
- k2 -> v2
- k2 -> v3
- k3 -> v2
- k3 -> v5
Note that both null
keys and values are not permitted in this map.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all key-value pairs from the multimap, leaving it empty.boolean
boolean
containsKey
(K key) boolean
containsValue
(V value) entrySet()
default void
forEach
(BiConsumer<K, V> action) Performs the given action for all key-value pairs contained in this multimap.void
forEachSet
(BiConsumer<K, Set<V>> action) Performs the given action for key-(value-set) pairs contained in this multimap.boolean
isEmpty()
keySet()
boolean
Stores a key-value pair in this multimap.boolean
putAll
(K key, Collection<? extends V> values) Stores a key-value pair in this multimap for each ofvalues
, all using the same key,key
.=boolean
Stores all key-value pairs ofmultimap
in this multimap.boolean
Removes a single key-value pair with the keykey
and the valuevalue
from this multimap, if such exists.boolean
Removes all values associated with the keykey
.boolean
removeAll
(K key, Collection<? extends V> values) Removes all key-value pairs forkey
andvalues
.int
size()
values()
-
Method Details
-
contains
- Returns:
true
if this multimap contains at least one key-value pair with the keykey
and the valuevalue
.
-
containsKey
- Returns:
true
if this multimap contains at least one key-value pair with the keykey
.
-
containsValue
- Returns:
true
if this multimap contains at least one key-value pair with the valuevalue
. Note that this operation may be slow compared tocontainsKey(Object)
in some implementations.
-
get
- Returns:
- an unmodifiable view of the values associated with
key
in this multimap, ifkey
is absent; otherwise, this returns an empty set.
-
put
Stores a key-value pair in this multimap.- Returns:
true
if the multimap changed.
-
putAll
Stores a key-value pair in this multimap for each ofvalues
, all using the same key,key
.= -
putAll
Stores all key-value pairs ofmultimap
in this multimap.- Returns:
true
if the multimap changed
-
remove
Removes a single key-value pair with the keykey
and the valuevalue
from this multimap, if such exists.- Returns:
true
if the multimap changed
-
removeAll
Removes all values associated with the keykey
.Once this method returns,
key
will not be mapped to any values, so it will not appear inkeySet()
.- Returns:
true
if the multimap changed.
-
removeAll
Removes all key-value pairs forkey
andvalues
.- Returns:
true
if the multimap changed.
-
keySet
- Returns:
- an unmodifiable view of all distinct keys contained in this multimap. Note that the key set contains a key if and only if this multimap maps that key to at least one value.
-
values
Collection<V> values()- Returns:
- an unmodifiable view collection containing the value
from each key-value pair contained in this multimap, without
collapsing duplicates (so
values().size() == size()
).
-
entrySet
- Returns:
- an unmodifiable view of all key-value pairs
contained in this multimap, as
Map.Entry
instances.
-
forEach
Performs the given action for all key-value pairs contained in this multimap. -
forEachSet
Performs the given action for key-(value-set) pairs contained in this multimap. -
clear
void clear()Removes all key-value pairs from the multimap, leaving it empty. -
isEmpty
boolean isEmpty()- Returns:
true
if this multimap is empty.
-
size
int size()- Returns:
- the number of key-value pairs in this multimap.
-