Class LinkedMultiValueMap<K,​V>

  • Type Parameters:
    K - the key type
    V - the value element type
    All Implemented Interfaces:
    MultiValueMap<K,​V>, java.io.Serializable, java.lang.Cloneable, java.util.Map<K,​java.util.List<V>>

    public class LinkedMultiValueMap<K,​V>
    extends java.lang.Object
    implements MultiValueMap<K,​V>, java.io.Serializable, java.lang.Cloneable

    This class is a clone of org.springframework.util.LinkedMultiValueMap

    Simple implementation of MultiValueMap that wraps a LinkedHashMap, storing multiple values in a LinkedList.

    This Map implementation is generally not thread-safe. It is primarily designed for data structures exposed from request objects, for use in a single thread only.

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      LinkedMultiValueMap()
      Create a new LinkedMultiValueMap that wraps a LinkedHashMap.
      LinkedMultiValueMap​(int initialCapacity)
      Create a new LinkedMultiValueMap that wraps a LinkedHashMap with the given initial capacity.
      LinkedMultiValueMap​(java.util.Map<K,​java.util.List<V>> otherMap)
      Copy constructor: Create a new LinkedMultiValueMap with the same mappings as the specified Map.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(K key, V value)
      Add the given single value to the current list of values for the given key.
      void addAll​(MultiValueMap<K,​V> values)
      Add all the values of the given MultiValueMap to the current values.
      void addAll​(K key, java.util.List<? extends V> values)
      Add all the values of the given list to the current list of values for the given key.
      void clear()  
      LinkedMultiValueMap<K,​V> clone()
      Create a regular copy of this Map.
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      LinkedMultiValueMap<K,​V> deepCopy()
      Create a deep copy of this Map.
      java.util.Set<java.util.Map.Entry<K,​java.util.List<V>>> entrySet()  
      boolean equals​(java.lang.Object obj)  
      java.util.List<V> get​(java.lang.Object key)  
      V getFirst​(K key)
      Return the first value for the given key.
      int hashCode()  
      boolean isEmpty()  
      java.util.Set<K> keySet()  
      java.util.List<V> put​(K key, java.util.List<V> value)  
      void putAll​(java.util.Map<? extends K,​? extends java.util.List<V>> map)  
      java.util.List<V> remove​(java.lang.Object key)  
      void set​(K key, V value)
      Set the given single value under the given key.
      void set​(K key, V[] values)
      Set the given values under the given key.
      void setAll​(java.util.Map<K,​V> values)
      Set the given values under.
      int size()  
      java.util.Map<K,​V> toSingleValueMap()
      Return a Map with the first values contained in this MultiValueMap.
      java.lang.String toString()  
      java.util.Collection<java.util.List<V>> values()  
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • LinkedMultiValueMap

        public LinkedMultiValueMap()
        Create a new LinkedMultiValueMap that wraps a LinkedHashMap.
      • LinkedMultiValueMap

        public LinkedMultiValueMap​(int initialCapacity)
        Create a new LinkedMultiValueMap that wraps a LinkedHashMap with the given initial capacity.
        Parameters:
        initialCapacity - the initial capacity
      • LinkedMultiValueMap

        public LinkedMultiValueMap​(java.util.Map<K,​java.util.List<V>> otherMap)
        Copy constructor: Create a new LinkedMultiValueMap with the same mappings as the specified Map. Note that this will be a shallow copy; its value-holding List entries will get reused and therefore cannot get modified independently.
        Parameters:
        otherMap - the Map whose mappings are to be placed in this Map
        See Also:
        clone(), deepCopy()
    • Method Detail

      • getFirst

        @Nullable
        public V getFirst​(K key)
        Description copied from interface: MultiValueMap
        Return the first value for the given key.
        Specified by:
        getFirst in interface MultiValueMap<K,​V>
        Parameters:
        key - the key
        Returns:
        the first value for the specified key, or null
      • add

        public void add​(K key,
                        @Nullable
                        V value)
        Description copied from interface: MultiValueMap
        Add the given single value to the current list of values for the given key.
        Specified by:
        add in interface MultiValueMap<K,​V>
        Parameters:
        key - the key
        value - the value to be added
      • addAll

        public void addAll​(K key,
                           java.util.List<? extends V> values)
        Description copied from interface: MultiValueMap
        Add all the values of the given list to the current list of values for the given key.
        Specified by:
        addAll in interface MultiValueMap<K,​V>
        Parameters:
        key - they key
        values - the values to be added
      • addAll

        public void addAll​(MultiValueMap<K,​V> values)
        Description copied from interface: MultiValueMap
        Add all the values of the given MultiValueMap to the current values.
        Specified by:
        addAll in interface MultiValueMap<K,​V>
        Parameters:
        values - the values to be added
      • set

        public void set​(K key,
                        @Nullable
                        V value)
        Description copied from interface: MultiValueMap
        Set the given single value under the given key.
        Specified by:
        set in interface MultiValueMap<K,​V>
        Parameters:
        key - the key
        value - the value to set
      • set

        public void set​(K key,
                        V[] values)
        Description copied from interface: MultiValueMap
        Set the given values under the given key.
        Specified by:
        set in interface MultiValueMap<K,​V>
        Parameters:
        key - the key
        values - the values
      • setAll

        public void setAll​(java.util.Map<K,​V> values)
        Description copied from interface: MultiValueMap
        Set the given values under.
        Specified by:
        setAll in interface MultiValueMap<K,​V>
        Parameters:
        values - the values
      • toSingleValueMap

        public java.util.Map<K,​V> toSingleValueMap()
        Description copied from interface: MultiValueMap
        Return a Map with the first values contained in this MultiValueMap.
        Specified by:
        toSingleValueMap in interface MultiValueMap<K,​V>
        Returns:
        a single value representation of this map
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
      • get

        @Nullable
        public java.util.List<V> get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
      • put

        @Nullable
        public java.util.List<V> put​(K key,
                                     java.util.List<V> value)
        Specified by:
        put in interface java.util.Map<K,​V>
      • remove

        @Nullable
        public java.util.List<V> remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
      • putAll

        public void putAll​(@NonNull
                           java.util.Map<? extends K,​? extends java.util.List<V>> map)
        Specified by:
        putAll in interface java.util.Map<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
      • keySet

        @NonNull
        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
      • values

        @NonNull
        public java.util.Collection<java.util.List<V>> values()
        Specified by:
        values in interface java.util.Map<K,​V>
      • entrySet

        @NonNull
        public java.util.Set<java.util.Map.Entry<K,​java.util.List<V>>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
      • deepCopy

        public LinkedMultiValueMap<K,​V> deepCopy()
        Create a deep copy of this Map.
        Returns:
        a copy of this Map, including a copy of each value-holding List entry (consistently using an independent modifiable LinkedList for each entry) along the lines of MultiValueMap.addAll semantics
        See Also:
        addAll(MultiValueMap), clone()
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object obj)
        Specified by:
        equals in interface java.util.Map<K,​V>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<K,​V>
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object