Class Multimap<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    Map<K,​List<V>>

    public class Multimap<K,​V>
    extends Object
    implements Map<K,​List<V>>
    A simple multi-valued map that wraps a LinkedHashMap with LinkedList to store multiple values. This class is NOT thread-safe.
    • Constructor Detail

      • Multimap

        public Multimap()
        Create an empty Multimap.
      • Multimap

        public Multimap​(int initialCapacity)
        Create an empty Multimap with a given initial capacity.
        Parameters:
        initialCapacity - the initial capacity
    • Method Detail

      • add

        public void add​(K key,
                        V value)
        Add a value to the list of values under the given key.
        Parameters:
        key - the key
        value - the value to add
      • addAll

        public void addAll​(K key,
                           Collection<? extends V> values)
        Add multiple values to the list of values under the given key.
        Parameters:
        key - the key
        values - the values to add
      • addAll

        public void addAll​(Multimap<K,​V> values)
        Add all values from the given Multimap to the current ones.
        Parameters:
        values - the values to add
      • set

        public void set​(K key,
                        V value)
        Set a value under the given key, replacing any existing single or multiple values.
        Parameters:
        key - the key
        value - the value to set
      • setAll

        public void setAll​(Map<K,​V> values)
        Set multiple values under the given key, replacing any existing single or multiple values.
        Parameters:
        values - the values to set
      • deepCopy

        public Multimap<K,​V> deepCopy()
        Clone this Multimap using a deep copy, including each stored value list.
        Returns:
        a deep copy of this Multimap
      • forEachElement

        public void forEachElement​(BiConsumer<? super K,​? super V> action)
        Performs the given action for each element, meaning once per each K-V entry in this Multimap, until all entries have been processed or the action throws an exception.
        Parameters:
        action - The action to be performed for each entry
        Throws:
        NullPointerException - if the specified action is null
        ConcurrentModificationException - if an entry is found to be removed during iteration
        Since:
        3.1.1
      • size

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

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

        public boolean containsKey​(Object key)
        Specified by:
        containsKey in interface Map<K,​V>
      • put

        public List<V> put​(K key,
                           List<V> value)
        Specified by:
        put in interface Map<K,​V>
      • putAll

        public void putAll​(Map<? extends K,​? extends List<V>> m)
        Specified by:
        putAll in interface Map<K,​V>
      • clear

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

        public Set<K> keySet()
        Specified by:
        keySet in interface Map<K,​V>