Package ratpack.func
Interface MultiValueMap<K,V>
-
- Type Parameters:
K
- The type of key objectsV
- The type of value objects
- All Superinterfaces:
Map<K,V>
- All Known Subinterfaces:
Form
public interface MultiValueMap<K,V> extends Map<K,V>
A map that may contain multiple values for a given key, but typically only one value.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description com.google.common.collect.ListMultimap<K,V>
asMultimap()
void
clear()
ThrowsUnsupportedOperationException
.static <K,V>
MultiValueMap<K,V>empty()
V
get(Object key)
Get the first value for the key, ornull
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)
ThrowsUnsupportedOperationException
.void
putAll(Map<? extends K,? extends V> m)
ThrowsUnsupportedOperationException
.V
remove(Object key)
ThrowsUnsupportedOperationException
.-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
-
-
-
-
Method Detail
-
empty
static <K,V> MultiValueMap<K,V> empty()
-
getAll
List<V> getAll(K key)
All of the values for the given key. An empty list if there are no values for the key.The returned list is immutable.
- Parameters:
key
- The key to return all values of- Returns:
- all of the values for the given key, or an empty list if there are no values for the key.
-
getAll
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. a traditional multi map).The returned map is immutable.
- Returns:
- A new view of the map where each map value is a list of all the values for the given key
-
get
@Nullable V get(Object key)
Get the first value for the key, ornull
if there are no values for the key.
-
put
V put(K key, V value)
ThrowsUnsupportedOperationException
.
-
remove
V remove(Object key)
ThrowsUnsupportedOperationException
.
-
putAll
void putAll(Map<? extends K,? extends V> m)
ThrowsUnsupportedOperationException
.
-
clear
void clear()
ThrowsUnsupportedOperationException
.
-
-