K
- The type of key objectsV
- The type of value objectspublic interface MultiValueMap<K,V> extends Map<K,V>
Unlike other multi map types, this type is optimized for the case where there is only one value for a key.
The map acts just like a normal Map
, but has extra methods for getting all values for a key.
All implementations of this type are immutable. Mutating operations throw UnsupportedOperationException
.
Where there is multiple values for a given key, retrieving a single value will return the first value, where the first value is intrinsic to the service in which the map is being used.
Modifier and Type | Method and Description |
---|---|
ListMultimap<K,V> |
asMultimap() |
void |
clear()
Throws
UnsupportedOperationException . |
V |
get(Object key)
Get the first value for the key, or
null if there are no values for the key. |
Map<K,List<V>> |
getAll()
Returns a new view of the map where each map value is a list of all the values for the given key (i.e.
|
List<V> |
getAll(K key)
All of the values for the given key.
|
V |
put(K key,
V value)
Throws
UnsupportedOperationException . |
void |
putAll(Map<? extends K,? extends V> m)
Throws
UnsupportedOperationException . |
V |
remove(Object key)
Throws
UnsupportedOperationException . |
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
List<V> getAll(K key)
The returned list is immutable.
key
- The key to return all values ofMap<K,List<V>> getAll()
The returned map is immutable.
@Nullable V get(Object key)
null
if there are no values for the key.V put(K key, V value)
UnsupportedOperationException
.
V remove(Object key)
UnsupportedOperationException
.
void putAll(Map<? extends K,? extends V> m)
UnsupportedOperationException
.
void clear()
UnsupportedOperationException
.
ListMultimap<K,V> asMultimap()