Class MultiMapUtils

    • Method Detail

      • emptyMultiValuedMap

        public static <K,​V> MultiValuedMap<K,​V> emptyMultiValuedMap()
        Returns immutable EMPTY_MULTI_VALUED_MAP with generic type safety.
        Type Parameters:
        K - the type of key in the map
        V - the type of value in the map
        Returns:
        immutable and empty MultiValuedMap
      • emptyIfNull

        public static <K,​V> MultiValuedMap<K,​V> emptyIfNull​(MultiValuedMap<K,​V> map)
        Returns an immutable empty MultiValuedMap if the argument is null, or the argument itself otherwise.
        Type Parameters:
        K - the type of key in the map
        V - the type of value in the map
        Parameters:
        map - the map, may be null
        Returns:
        an empty MultiValuedMap if the argument is null
      • isEmpty

        public static boolean isEmpty​(MultiValuedMap<?,​?> map)
        Null-safe check if the specified MultiValuedMap is empty.

        If the provided map is null, returns true.

        Parameters:
        map - the map to check, may be null
        Returns:
        true if the map is empty or null
      • getCollection

        public static <K,​V> java.util.Collection<V> getCollection​(MultiValuedMap<K,​V> map,
                                                                        K key)
        Gets a Collection from MultiValuedMap in a null-safe manner.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - the MultiValuedMap to use
        key - the key to look up
        Returns:
        the Collection in the MultiValuedMap, or null if input map is null
      • getValuesAsList

        public static <K,​V> java.util.List<V> getValuesAsList​(MultiValuedMap<K,​V> map,
                                                                    K key)
        Gets a List from MultiValuedMap in a null-safe manner.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - the MultiValuedMap to use
        key - the key to look up
        Returns:
        the Collection in the MultiValuedMap as List, or null if input map is null
      • getValuesAsSet

        public static <K,​V> java.util.Set<V> getValuesAsSet​(MultiValuedMap<K,​V> map,
                                                                  K key)
        Gets a Set from MultiValuedMap in a null-safe manner.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - the MultiValuedMap to use
        key - the key to look up
        Returns:
        the Collection in the MultiValuedMap as Set, or null if input map is null
      • getValuesAsBag

        public static <K,​V> Bag<V> getValuesAsBag​(MultiValuedMap<K,​V> map,
                                                        K key)
        Gets a Bag from MultiValuedMap in a null-safe manner.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - the MultiValuedMap to use
        key - the key to look up
        Returns:
        the Collection in the MultiValuedMap as Bag, or null if input map is null
      • newListValuedHashMap

        public static <K,​V> ListValuedMap<K,​V> newListValuedHashMap()
        Creates a ListValuedMap with an ArrayList as collection class to store the values mapped to a key.
        Type Parameters:
        K - the key type
        V - the value type
        Returns:
        a new ListValuedMap
      • newSetValuedHashMap

        public static <K,​V> SetValuedMap<K,​V> newSetValuedHashMap()
        Creates a SetValuedMap with an HashSet as collection class to store the values mapped to a key.
        Type Parameters:
        K - the key type
        V - the value type
        Returns:
        a new SetValuedMap
      • unmodifiableMultiValuedMap

        public static <K,​V> MultiValuedMap<K,​V> unmodifiableMultiValuedMap​(MultiValuedMap<? extends K,​? extends V> map)
        Returns an UnmodifiableMultiValuedMap backed by the given map.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - the MultiValuedMap to decorate, must not be null
        Returns:
        an unmodifiable MultiValuedMap backed by the provided map
        Throws:
        java.lang.NullPointerException - if map is null