Interface MultivalueMap<K, v extends @Nullable Object>

Type Parameters:
K - the key type
v - the value element type
All Superinterfaces:
Map<K,List<v>>
All Known Implementing Classes:
HttpComponentsHeadersAdapter, JettyHeadersAdapter, LinkedMultivalueMap, MultivalueMapAdapter, Netty4HeadersAdapter, StompHeaders

public interface MultivalueMap<K, v extends @Nullable Object> extends Map<K,List<v>>
Extension of the Map interface that stores multiple values.
Since:
3.0
Author:
Arjen Poutsma
  • Method Details

    • getFirst

      @Nullable v getFirst(K key)
      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

      void add(K key, @Nullable v value)
      Add the given single value to the current list of values for the given key.
      Parameters:
      key - the key
      value - the value to be added
    • addAll

      void addAll(K key, List<? extends vvalues)
      Add all the values of the given list to the current list of values for the given key.
      Parameters:
      key - they key
      values - the values to be added
      Since:
      5.0
    • addAll

      void addAll(MultivalueMap<K,vvalues)
      Add all the values of the given MultivalueMap to the current values.
      Parameters:
      values - the values to be added
      Since:
      5.0
    • addIfAbsent

      default void addIfAbsent(K key, @Nullable v value)
      Add the given value, only when the map does not contain the given key.
      Parameters:
      key - the key
      value - the value to be added
      Since:
      5.2
    • set

      void set(K key, @Nullable v value)
      Set the given single value under the given key.
      Parameters:
      key - the key
      value - the value to set
    • setAll

      void setAll(Map<K,vvalues)
      Set the given values in this MultivalueMap.
      Parameters:
      values - the values
    • toSinglevalueMap

      Map<K,v> toSinglevalueMap()
      Return a Map with the first values contained in this MultivalueMap.

      The difference between this method and asSinglevalueMap() 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

      default Map<K,v> asSinglevalueMap()
      Return this map as a Map with the first values contained in this MultivalueMap.

      The difference between this method and toSinglevalueMap() 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

      static <K,v> MultivalueMap<K,v> fromSinglevalue(Map<K,v> map)
      Return a MultivalueMap<K, v> that adapts the given single-value Map<K, v>.

      The returned map cannot map multiple values to the same key, and doing so results in an UnsupportedOperationException. Use fromMultivalue(Map) to support multiple values.

      Type Parameters:
      K - the key type
      v - 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

      static <K,v> MultivalueMap<K,v> fromMultivalue(Map<K,List<v>> map)
      Return a MultivalueMap<K, v> that adapts the given multi-value Map<K, List<v>>.
      Type Parameters:
      K - the key type
      v - 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: