Class MultiMap<K,​V>

  • All Implemented Interfaces:
    java.util.Map<K,​java.util.List<V>>

    public class MultiMap<K,​V>
    extends java.lang.Object
    implements java.util.Map<K,​java.util.List<V>>
    • 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
      MultiMap()  
      MultiMap​(boolean noduplicates)  
      MultiMap​(MultiMap<S,​T> other)  
      MultiMap​(java.lang.Class<? extends K> keyClass, java.lang.Class<? extends V> valueClass, boolean noduplicates)  
      MultiMap​(java.util.Map<? extends K,​? extends java.util.Collection<? extends V>> other)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(K key, V value)  
      boolean addAll​(java.util.Map<? extends K,​? extends java.util.Collection<? extends V>> other)  
      boolean addAll​(K key, java.util.Collection<? extends V> value)  
      java.util.Iterator<V> all()  
      java.util.List<V> allValues()
      Return a collection with all values
      void clear()  
      java.util.List<V> compute​(K key, java.util.function.BiFunction<? super K,​? super java.util.List<V>,​? extends java.util.List<V>> remappingFunction)  
      java.util.List<V> computeIfAbsent​(K key, java.util.function.Function<? super K,​? extends java.util.List<V>> mappingFunction)  
      java.util.List<V> computeIfPresent​(K key, java.util.function.BiFunction<? super K,​? super java.util.List<V>,​? extends java.util.List<V>> remappingFunction)  
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set<java.util.Map.Entry<K,​java.util.List<V>>> entrySet()  
      boolean equals​(java.lang.Object obj)  
      java.util.Map<K,​V> flatten()  
      void forEach​(java.util.function.BiConsumer<? super K,​? super java.util.List<V>> action)  
      static <T extends java.lang.Comparable<? super T>>
      java.lang.String
      format​(java.util.Map<T,​? extends java.util.Collection<?>> map)  
      java.util.List<V> get​(java.lang.Object key)  
      java.util.List<V> getOrDefault​(java.lang.Object key, java.util.List<V> defaultValue)  
      MultiMap<K,​V> groupBy​(java.util.Collection<? extends V> collection, java.util.function.Function<? super V,​? extends K> classifier)
      Index a collection.
      int hashCode()  
      boolean isEmpty()  
      java.util.Iterator<V> iterate​(K key)  
      java.util.Set<K> keySet()  
      java.util.List<V> merge​(K key, java.util.List<V> value, java.util.function.BiFunction<? super java.util.List<V>,​? super java.util.List<V>,​? extends java.util.List<V>> remappingFunction)  
      java.util.List<V> put​(K key, java.util.List<V> value)  
      void putAll​(java.util.Map<? extends K,​? extends java.util.List<V>> m)  
      java.util.List<V> putIfAbsent​(K key, java.util.List<V> value)  
      java.util.List<V> remove​(java.lang.Object key)  
      boolean remove​(java.lang.Object key, java.lang.Object value)  
      boolean removeAll​(K key, java.util.Collection<? extends V> value)  
      boolean removeValue​(K key, V value)  
      java.util.List<V> replace​(K key, java.util.List<V> value)  
      boolean replace​(K key, java.util.List<V> oldValue, java.util.List<V> newValue)  
      void replaceAll​(java.util.function.BiFunction<? super K,​? super java.util.List<V>,​? extends java.util.List<V>> function)  
      int size()  
      java.lang.String toString()  
      MultiMap<V,​K> transpose()  
      MultiMap<V,​K> transpose​(boolean noduplicates)  
      java.util.Collection<java.util.List<V>> values()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MultiMap

        public MultiMap()
      • MultiMap

        public MultiMap​(boolean noduplicates)
      • MultiMap

        public MultiMap​(java.lang.Class<? extends K> keyClass,
                        java.lang.Class<? extends V> valueClass,
                        boolean noduplicates)
      • MultiMap

        public MultiMap​(java.util.Map<? extends K,​? extends java.util.Collection<? extends V>> other)
      • MultiMap

        public MultiMap​(MultiMap<S,​T> other)
    • Method Detail

      • add

        public boolean add​(K key,
                           V value)
      • addAll

        public boolean addAll​(K key,
                              java.util.Collection<? extends V> value)
      • addAll

        public boolean addAll​(java.util.Map<? extends K,​? extends java.util.Collection<? extends V>> other)
      • removeValue

        public boolean removeValue​(K key,
                                   V value)
      • removeAll

        public boolean removeAll​(K key,
                                 java.util.Collection<? extends V> value)
      • iterate

        public java.util.Iterator<V> iterate​(K key)
      • all

        public java.util.Iterator<V> all()
      • flatten

        public java.util.Map<K,​V> flatten()
      • transpose

        public MultiMap<V,​K> transpose​(boolean noduplicates)
      • allValues

        public java.util.List<V> allValues()
        Return a collection with all values
        Returns:
        all values
      • format

        public static <T extends java.lang.Comparable<? super T>> java.lang.String format​(java.util.Map<T,​? extends java.util.Collection<?>> 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

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

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

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

        public void putAll​(java.util.Map<? extends K,​? extends java.util.List<V>> m)
        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

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

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

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

        public java.util.List<V> getOrDefault​(java.lang.Object key,
                                              java.util.List<V> defaultValue)
        Specified by:
        getOrDefault in interface java.util.Map<K,​V>
      • forEach

        public void forEach​(java.util.function.BiConsumer<? super K,​? super java.util.List<V>> action)
        Specified by:
        forEach in interface java.util.Map<K,​V>
      • replaceAll

        public void replaceAll​(java.util.function.BiFunction<? super K,​? super java.util.List<V>,​? extends java.util.List<V>> function)
        Specified by:
        replaceAll in interface java.util.Map<K,​V>
      • putIfAbsent

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

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

        public boolean replace​(K key,
                               java.util.List<V> oldValue,
                               java.util.List<V> newValue)
        Specified by:
        replace in interface java.util.Map<K,​V>
      • replace

        public java.util.List<V> replace​(K key,
                                         java.util.List<V> value)
        Specified by:
        replace in interface java.util.Map<K,​V>
      • computeIfAbsent

        public java.util.List<V> computeIfAbsent​(K key,
                                                 java.util.function.Function<? super K,​? extends java.util.List<V>> mappingFunction)
        Specified by:
        computeIfAbsent in interface java.util.Map<K,​V>
      • computeIfPresent

        public java.util.List<V> computeIfPresent​(K key,
                                                  java.util.function.BiFunction<? super K,​? super java.util.List<V>,​? extends java.util.List<V>> remappingFunction)
        Specified by:
        computeIfPresent in interface java.util.Map<K,​V>
      • compute

        public java.util.List<V> compute​(K key,
                                         java.util.function.BiFunction<? super K,​? super java.util.List<V>,​? extends java.util.List<V>> remappingFunction)
        Specified by:
        compute in interface java.util.Map<K,​V>
      • merge

        public java.util.List<V> merge​(K key,
                                       java.util.List<V> value,
                                       java.util.function.BiFunction<? super java.util.List<V>,​? super java.util.List<V>,​? extends java.util.List<V>> remappingFunction)
        Specified by:
        merge in interface java.util.Map<K,​V>
      • hashCode

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

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

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

        public MultiMap<K,​V> groupBy​(java.util.Collection<? extends V> collection,
                                           java.util.function.Function<? super V,​? extends K> classifier)
        Index a collection.
        Parameters:
        collection - the collection to index
        classifier - the function to map a value in the collection to the key
        Returns:
        the current map