Package ratpack.util

Interface MultiValueMap<K,​V>

  • Type Parameters:
    K - The type of key objects
    V - The type of value objects
    All Superinterfaces:
    java.util.Map<K,​V>
    All Known Subinterfaces:
    Form

    public interface MultiValueMap<K,​V>
    extends java.util.Map<K,​V>
    A map that may contain multiple values for a given key, but typically only one value.

    Unlike other multi map types, this type is optimized for the case where there is only one value for a key. The map acts just like a normal Map, but has extra methods for getting all values for a key.

    All implementations of this type are immutable. Mutating operations throw UnsupportedOperationException.

    Where there is multiple values for a given key, retrieving a single value will return the first value, where the first value is intrinsic to the service in which the map is being used.

    • 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>
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      com.google.common.collect.ListMultimap<K,​V> asMultimap()  
      void clear()
      Throws UnsupportedOperationException.
      static <K,​V>
      MultiValueMap<K,​V>
      empty()  
      V get​(java.lang.Object key)
      Get the first value for the key, or null if there are no values for the key.
      java.util.Map<K,​java.util.List<V>> getAll()
      Returns a new view of the map where each map value is a list of all the values for the given key (i.e.
      java.util.List<V> getAll​(K key)
      All of the values for the given key.
      V put​(K key, V value)
      Throws UnsupportedOperationException.
      void putAll​(java.util.Map<? extends K,​? extends V> m)
      Throws UnsupportedOperationException.
      V remove​(java.lang.Object key)
      Throws UnsupportedOperationException.
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
    • Method Detail

      • getAll

        java.util.List<V> getAll​(K key)
        All of the values for the given key. An empty list if there are no values for the key.

        The returned list is immutable.

        Parameters:
        key - The key to return all values of
        Returns:
        all of the values for the given key, or an empty list if there are no values for the key.
      • getAll

        java.util.Map<K,​java.util.List<V>> getAll()
        Returns a new view of the map where each map value is a list of all the values for the given key (i.e. a traditional multi map).

        The returned map is immutable.

        Returns:
        A new view of the map where each map value is a list of all the values for the given key
      • get

        @Nullable
        V get​(java.lang.Object key)
        Get the first value for the key, or null if there are no values for the key.
        Specified by:
        get in interface java.util.Map<K,​V>
        Parameters:
        key - The key to obtain the first value for
        Returns:
        The first value for the given key, or null if there are no values for the given key
      • put

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

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

        void putAll​(java.util.Map<? extends K,​? extends V> m)
        Throws UnsupportedOperationException.
        Specified by:
        putAll in interface java.util.Map<K,​V>
      • clear

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

        com.google.common.collect.ListMultimap<K,​V> asMultimap()