K
- the type of the map's keysV
- the type of the map's valuespublic interface MultiMap<K,V>
extends java.io.Serializable
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the mappings from this map (optional operation).
|
default java.util.Collection<V> |
compute(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
Attempts to compute a mapping for the specified key and its current
mapped value (or null if there is no current mapping).
|
default java.util.Collection<V> |
computeIfAbsent(K key,
java.util.function.Function<? super K,? extends V> mappingFunction)
If the specified key is not already associated with a value (or is mapped
to null), attempts to compute its value using the given mapping function
and enters it into this map unless null.
|
default java.util.Collection<V> |
computeIfPresent(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
If the value for the specified key is present and non-null, attempts to
compute a new mapping given the key and its current mapped value.
|
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key.
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified value.
|
java.util.Collection<java.util.Map.Entry<K,V>> |
entries()
Returns a collection view of the mappings contained in this map.
|
default void |
forEach(java.util.function.BiConsumer<? super K,? super V> action)
Performs the given action for each entry in this map until all entries
have been processed or the action throws an exception.
|
java.util.Collection<V> |
get(java.lang.Object key)
Returns the values to which the specified key is mapped, or null if this
map contains no mapping for the key.
|
java.util.Collection<V> |
getEmptyCollection()
Provides an empty collection of the appropriate type to hold values.
|
default java.util.Collection<V> |
getOrDefault(java.lang.Object key,
java.util.Collection<V> defaultValues)
Returns the values to which the specified key is mapped, or defaultValues
if this map contains no mapping for the key.
|
boolean |
isEmpty()
Returns true if this map contains no key-value mappings.
|
java.util.Set<K> |
keySet()
Returns a set view of the keys contained in this map.
|
default java.util.Collection<V> |
merge(K key,
V value,
java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
If the specified key is not already associated with a value or is
associated with null, associates it with the given non-null value.
|
void |
put(K key,
java.util.Collection<V> values)
Associates the specified values with the specified key in this map
(optional operation).
|
void |
put(K key,
V value)
Associates the specified value with the specified key in this map
(optional operation).
|
void |
putAll(java.util.Map<? extends K,? extends V> map)
Copies all of the mappings from the specified map to this map (optional
operation).
|
void |
putAll(MultiMap<? extends K,? extends V> map)
Copies all of the mappings from the specified multimap to this map
(optional operation).
|
default void |
putIfAbsent(K key,
java.util.Collection<V> values)
If the specified key is not already associated with a value (or is mapped
to null) associates it with the given values and returns null, else
returns the current value.
|
default void |
putIfAbsent(K key,
V value)
If the specified key is not already associated with a value (or is mapped
to null) associates it with the given value and returns null, else
returns the current value.
|
java.util.Collection<V> |
remove(java.lang.Object key)
Removes the mapping for a key from this map if it is present (optional
operation).
|
default boolean |
remove(java.lang.Object key,
java.util.Collection<java.lang.Object> values)
Removes the entry for the specified key only if it is currently mapped to
the specified values.
|
default java.util.Collection<V> |
replace(K key,
java.util.Collection<V> values)
Replaces all existing entries for the specified key only if it is
currently mapped to some value.
|
default boolean |
replace(K key,
java.util.Collection<V> oldValues,
java.util.Collection<V> newValues)
Replaces all entries for the specified key only if currently mapped to
the specified values.
|
default java.util.Collection<V> |
replace(K key,
V value)
Replaces all existing entries for the specified key only if it is
currently mapped to some value.
|
default boolean |
replace(K key,
V oldValue,
V newValue)
Replaces a single entry for the specified key only if currently mapped to
the specified value.
|
default void |
replaceAll(java.util.function.BiFunction<? super K,? 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()
Returns the number of key-value mappings in this map.
|
java.util.Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
void clear()
default java.util.Collection<V> compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
key
- key with which the specified value is to be associatedremappingFunction
- the function to compute a valuedefault java.util.Collection<V> computeIfAbsent(K key, java.util.function.Function<? super K,? extends V> mappingFunction)
key
- key with which the specified value is to be associatedmappingFunction
- the function to compute a valuedefault java.util.Collection<V> computeIfPresent(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
key
- key with which the specified value is to be associatedremappingFunction
- the function to compute a valueboolean containsKey(java.lang.Object key)
key
- key whose presence in this map is to be testedboolean containsValue(java.lang.Object value)
value
- value whose presence in this map is to be testedjava.util.Collection<java.util.Map.Entry<K,V>> entries()
default void forEach(java.util.function.BiConsumer<? super K,? super V> action)
action
- The action to be performed for each entryjava.util.Collection<V> get(java.lang.Object key)
key
- the key to get values forjava.util.Collection<V> getEmptyCollection()
default java.util.Collection<V> getOrDefault(java.lang.Object key, java.util.Collection<V> defaultValues)
key
- the key whose associated values are to be returneddefaultValues
- the default mapping of the keyboolean isEmpty()
java.util.Set<K> keySet()
default java.util.Collection<V> merge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
key
- key with which the resulting value is to be associatedvalue
- the non-null value to be merged with the existing values
associated with the key or, if no existing value or a null
value is associated with the key, to be associated with the
keyremappingFunction
- the function to recompute a value if presentvoid put(K key, java.util.Collection<V> values)
key
- key with which the specified value is to be associatedvalues
- values to be associated with the specified keyvoid put(K key, V value)
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyvoid putAll(java.util.Map<? extends K,? extends V> map)
map
- mappings to be stored in this mapvoid putAll(MultiMap<? extends K,? extends V> map)
map
- mappings to be stored in this mapdefault void putIfAbsent(K key, java.util.Collection<V> values)
key
- key with which the specified value is to be associatedvalues
- values to be associated with the specified keydefault void putIfAbsent(K key, V value)
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyjava.util.Collection<V> remove(java.lang.Object key)
key
- key whose mappings are to be removed from the mapdefault boolean remove(java.lang.Object key, java.util.Collection<java.lang.Object> values)
key
- key with which the specified value is associatedvalues
- values expected to be associated with the specified keydefault java.util.Collection<V> replace(K key, java.util.Collection<V> values)
key
- key with which the specified value is associatedvalues
- values to be associated with the specified keydefault boolean replace(K key, java.util.Collection<V> oldValues, java.util.Collection<V> newValues)
key
- key with which the specified values are associatedoldValues
- values expected to be associated with the specified keynewValues
- values to be associated with the specified keydefault java.util.Collection<V> replace(K key, V value)
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keydefault boolean replace(K key, V oldValue, V newValue)
key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keynewValue
- value to be associated with the specified keydefault void replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)
function
- the function to apply to each entryint size()
java.util.Collection<V> values()