Interface MultiMap<K,V>

Type Parameters:
K - the type of keys maintained by this multimap
V - the type of mapped values

public interface MultiMap<K,V>
A MultiMap is like a Map except that a key can be bound to multiple values. It is similar to Map<K,Collection<V>>, but not identical because in a multimap, each key and value is stored as an individual entry. This means that the iteration order and size() will be different. If you actually need the Map<K,Collection<V>> semantics, then call the map() method.
Author:
cdivilly
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    Test if this object contains the specified key.
    Get each key value pair in this multi-map.
    default V
    get(Object key)
    Get the first value associated with the specified key.
    default boolean
    Returns true if this MultiMap contains no key-value mappings.
    default Set<K>
    The set of keys in this object
    map()
    Represent this MultiMap as a Map<K,Collection<V>> data structure, where values are grouped by key.
    default int
    The number of entries in this MultiMap.
    Get all the values associated with the specified key.
  • Method Details

    • containsKey

      default boolean containsKey(Object key)
      Test if this object contains the specified key.
      Parameters:
      key - The key to search for
      Returns:
      true if the key exists, false otherwise
    • entries

      Collection<Map.Entry<K,V>> entries()
      Get each key value pair in this multi-map.
      Returns:
      Collection of all Map.Entrys in this multi map.
    • get

      default V get(Object key)
      Get the first value associated with the specified key.
      Parameters:
      key - The key to search for
      Returns:
      The first value associated with the key, or null if no values are associated with the key
    • isEmpty

      default boolean isEmpty()
      Returns true if this MultiMap contains no key-value mappings.
      Returns:
      true if this MultiMap contains no key-value mappings
    • keySet

      default Set<K> keySet()
      The set of keys in this object
      Returns:
      The key set
    • map

      Map<K,Collection<V>> map()
      Represent this MultiMap as a Map<K,Collection<V>> data structure, where values are grouped by key.
      Returns:
      Map instance
    • size

      default int size()
      The number of entries in this MultiMap. Note that this method returns the number of entries, not the number of keys as a Map would. Consider the following MultiMap
       { a = b, c = d, a = e }
       
      The size() of this MultiMap is 3. Note that the Map.size() value returned by the Map instance returned from the map() method would be 2, because there are only two distinct keys.
      Returns:
      the number of values in the multimap
    • values

      Collection<V> values(Object key)
      Get all the values associated with the specified key.
      Parameters:
      key - The name of the key
      Returns:
      The values associated with the key, or returns null if the key is not present in the MultiMap