Interface MultiMap<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Known Implementing Classes:
IdMultiHashMap, MultiHashMap, SynchronizedMultiMap, TypeMultiHashMap, UnmodifiableMultiMap
public interface MultiMap<K,V>
A map that associates each key with a collection of values rather
than a single value. Putting several values under one key keeps all
of them;
get(K) returns the whole collection for a key (an
empty collection if the key is absent), and size() counts
key/value pairs, not keys.
Keys and values are never null; the mutators reject
null arguments. The collections returned by get(K), keySet(), values(), and asMap() are
unmodifiable views.
An implementation reports whether it accepts changes through isModifiable(); a read-only implementation throws UnsupportedException from its mutators. Whether duplicate
values are kept under a key is implementation-defined.
See MultiHashMap for the standard implementation and Collections for read-only and synchronized wrappers.-
Method Summary
Modifier and TypeMethodDescriptionMap<K, Collection<V>> asMap()Gets a Map of this MultiMap.voidclear()Removes all of the mappings from this map.booleancontainsKey(K key) Tests if this map contains a mapping for the specified key.booleancontainsKeyValue(K key, V value) Tests the map contains the key and value specified.booleancontainsValue(V value) Tests the map contains the value specified.Gets the values to which the specified key is mapped.booleanisEmpty()Tests if this map contains no key-value mappings.booleanTests if this map can be modified.keySet()Returns an immutable Collection view of the keys contained in this map.voidAssociates the specified value with the specified key in this map.voidputAll(Map<K, Collection<? extends V>> map) Stores a map of keys and values inside this map.voidputAll(K key, Collection<? extends V> values) Adds a collection of values to to a key in this mapvoidStores a Multimap inside this map.voidRemoves the mapping for a key and all its related values.voidRemoves a specific key/value pair from the map.voidremoveValue(V value) Removes a value.longsize()Returns the number of key-value mappings in this map.values()Returns a Collection view of the values contained in this map.
-
Method Details
-
isModifiable
boolean isModifiable()Tests if this map can be modified.- Returns:
trueif the map can be modified,falseif read-only
-
size
long size()Returns the number of key-value mappings in this map.- Returns:
- the number of key-value mappings in this map
-
isEmpty
boolean isEmpty()Tests if this map contains no key-value mappings.- Returns:
trueif this map contains no key-value mappings,falseotherwise
-
containsKey
Tests if this map contains a mapping for the specified key.- Parameters:
key- the key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key,falseotherwise- Throws:
NullArgumentException-keyisnull
-
containsValue
Tests the map contains the value specified.- Parameters:
value- the value to search for- Returns:
trueif the map contains the value,falseotherwise- Throws:
NullArgumentException-valueisnull
-
containsKeyValue
Tests the map contains the key and value specified.- Parameters:
key- the keyvalue- the value- Returns:
trueif the map contains the key/value pair,falseotherwise- Throws:
NullArgumentException-keyorvalueisnull
-
get
Gets the values to which the specified key is mapped. If the key is not defined, this method returns an empty list.- Parameters:
key- the key- Returns:
- a collection of the values for the given key or an empty collection if the key is not found
- Throws:
NullArgumentException-keyisnull
-
put
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Throws:
NullArgumentException-keyorvalueisnullUnsupportedException- map is not modifiable
-
putAll
Adds a collection of values to to a key in this map- Parameters:
key- the keyvalues- the values- Throws:
NullArgumentException-keyorvaluesisnullUnsupportedException- map is not modifiable
-
putAll
Stores a map of keys and values inside this map.- Parameters:
map- the map to store- Throws:
NullArgumentException-mapisnullUnsupportedException- map is not modifiable
-
putAll
Stores a Multimap inside this map.- Parameters:
map- the map to store- Throws:
NullArgumentException-mapisnullUnsupportedException- map is not modifiable
-
remove
Removes the mapping for a key and all its related values.- Parameters:
key- whose mapping is to be removed from the map- Throws:
NullArgumentException-keyisnullUnsupportedException- map is not modifiable
-
remove
Removes a specific key/value pair from the map. The item is removed from the collection mapped to the specified key. Other values attached to that key are unaffected.- Parameters:
key- the keyvalue- the value to remove- Throws:
NullArgumentException-keyorvalueisnullUnsupportedException- map is not modifiable
-
removeValue
Removes a value.- Parameters:
value- to be removed from the map- Throws:
NullArgumentException-valueisnull
-
clear
void clear()Removes all of the mappings from this map. The map will be empty after this call returns.- Throws:
UnsupportedException- map is not modifiable
-
keySet
Collection<K> keySet()Returns an immutable Collection view of the keys contained in this map.- Returns:
- a set view of the keys contained in this map
-
values
Collection<V> values()Returns a Collection view of the values contained in this map.- Returns:
- a collection of the values
-
asMap
-