Package org.springframework.util
Interface MultiValueMap<K,V>
- Type Parameters:
K
- the key typeV
- the value element type
- All Known Implementing Classes:
HttpComponentsHeadersAdapter
,HttpHeaders
,JettyHeadersAdapter
,LinkedMultiValueMap
,MultiValueMapAdapter
,Netty4HeadersAdapter
,Netty5HeadersAdapter
,StompHeaders
,WebSocketHttpHeaders
Extension of the
Map
interface that stores multiple values.- Since:
- 3.0
- Author:
- Arjen Poutsma
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the given single value to the current list of values for the given key.void
Add all the values of the given list to the current list of values for the given key.void
addAll
(MultiValueMap<K, V> values) Add all the values of the givenMultiValueMap
to the current values.default void
addIfAbsent
(K key, V value) Return this map as aMap
with the first values contained in thisMultiValueMap
.static <K,
V> MultiValueMap<K, V> fromMultiValue
(Map<K, List<V>> map) Return aMultiValueMap<K, V>
that adapts the given multi-valueMap<K, List<V>>
.static <K,
V> MultiValueMap<K, V> fromSingleValue
(Map<K, V> map) Return aMultiValueMap<K, V>
that adapts the given single-valueMap<K, V>
.Return the first value for the given key.void
Set the given single value under the given key.void
Set the given values under.Return aMap
with the first values contained in thisMultiValueMap
.Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Method Details
-
getFirst
Return the first value for the given key.- Parameters:
key
- the key- Returns:
- the first value for the specified key, or
null
if none
-
add
Add the given single value to the current list of values for the given key.- Parameters:
key
- the keyvalue
- the value to be added
-
addAll
Add all the values of the given list to the current list of values for the given key.- Parameters:
key
- they keyvalues
- the values to be added- Since:
- 5.0
-
addAll
Add all the values of the givenMultiValueMap
to the current values.- Parameters:
values
- the values to be added- Since:
- 5.0
-
addIfAbsent
- Parameters:
key
- the keyvalue
- the value to be added- Since:
- 5.2
-
set
Set the given single value under the given key.- Parameters:
key
- the keyvalue
- the value to set
-
setAll
Set the given values under.- Parameters:
values
- the values.
-
toSingleValueMap
Return aMap
with the first values contained in thisMultiValueMap
. The difference between this method andasSingleValueMap()
is that this method returns a copy of the entries of this map, whereas the latter returns a view.- Returns:
- a single value representation of this map
-
asSingleValueMap
Return this map as aMap
with the first values contained in thisMultiValueMap
. The difference between this method andtoSingleValueMap()
is that this method returns a view of the entries of this map, whereas the latter returns a copy.- Returns:
- a single value representation of this map
- Since:
- 6.2
-
fromSingleValue
Return aMultiValueMap<K, V>
that adapts the given single-valueMap<K, V>
. The returned map cannot map multiple values to the same key, and doing so results in anUnsupportedOperationException
. UsefromMultiValue(Map)
to support multiple values.- Type Parameters:
K
- the key typeV
- the value element type- Parameters:
map
- the map to be adapted- Returns:
- a multi-value-map that delegates to
map
- Since:
- 6.2
- See Also:
-
fromMultiValue
Return aMultiValueMap<K, V>
that adapts the given multi-valueMap<K, List<V>>
.- Type Parameters:
K
- the key typeV
- the value element type- Parameters:
map
- the map to be adapted- Returns:
- a multi-value-map that delegates to
map
- Since:
- 6.2
- See Also:
-