Interface MultiMap<K,V>

Type Parameters:
K - the key type
V - the value type
All Known Implementing Classes:
IdMultiHashMap, MultiHashMap, SynchronizedMultiMap, TypeMultiHashMap, UnmodifiableMultiMap

public interface MultiMap<K,V>
A map that associates each key with a collection of values rather than a single value. Putting several values under one key keeps all of them; get(K) returns the whole collection for a key (an empty collection if the key is absent), and size() counts key/value pairs, not keys. Keys and values are never null; the mutators reject null arguments. The collections returned by get(K), keySet(), values(), and asMap() are unmodifiable views. An implementation reports whether it accepts changes through isModifiable(); a read-only implementation throws UnsupportedException from its mutators. Whether duplicate values are kept under a key is implementation-defined. See MultiHashMap for the standard implementation and Collections for read-only and synchronized wrappers.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets a Map of this MultiMap.
    void
    Removes all of the mappings from this map.
    boolean
    Tests if this map contains a mapping for the specified key.
    boolean
    containsKeyValue(K key, V value)
    Tests the map contains the key and value specified.
    boolean
    Tests the map contains the value specified.
    get(K key)
    Gets the values to which the specified key is mapped.
    boolean
    Tests if this map contains no key-value mappings.
    boolean
    Tests if this map can be modified.
    Returns an immutable Collection view of the keys contained in this map.
    void
    put(K key, V value)
    Associates the specified value with the specified key in this map.
    void
    putAll(Map<K, Collection<? extends V>> map)
    Stores a map of keys and values inside this map.
    void
    putAll(K key, Collection<? extends V> values)
    Adds a collection of values to to a key in this map
    void
    putAll(MultiMap<K, ? extends V> map)
    Stores a Multimap inside this map.
    void
    remove(K key)
    Removes the mapping for a key and all its related values.
    void
    remove(K key, V value)
    Removes a specific key/value pair from the map.
    void
    removeValue(V value)
    Removes a value.
    long
    Returns the number of key-value mappings in this map.
    Returns a Collection view of the values contained in this map.
  • Method Details

    • isModifiable

      boolean isModifiable()
      Tests if this map can be modified.
      Returns:
      true if the map can be modified, false if read-only
    • size

      long size()
      Returns the number of key-value mappings in this map.
      Returns:
      the number of key-value mappings in this map
    • isEmpty

      boolean isEmpty()
      Tests if this map contains no key-value mappings.
      Returns:
      true if this map contains no key-value mappings, false otherwise
    • containsKey

      boolean containsKey(K key)
      Tests if this map contains a mapping for the specified key.
      Parameters:
      key - the key whose presence in this map is to be tested
      Returns:
      true if this map contains a mapping for the specified key, false otherwise
      Throws:
      NullArgumentException - key is null
    • containsValue

      boolean containsValue(V value)
      Tests the map contains the value specified.
      Parameters:
      value - the value to search for
      Returns:
      true if the map contains the value, false otherwise
      Throws:
      NullArgumentException - value is null
    • containsKeyValue

      boolean containsKeyValue(K key, V value)
      Tests the map contains the key and value specified.
      Parameters:
      key - the key
      value - the value
      Returns:
      true if the map contains the key/value pair, false otherwise
      Throws:
      NullArgumentException - key or value is null
    • get

      Collection<V> get(K key)
      Gets the values to which the specified key is mapped. If the key is not defined, this method returns an empty list.
      Parameters:
      key - the key
      Returns:
      a collection of the values for the given key or an empty collection if the key is not found
      Throws:
      NullArgumentException - key is null
    • put

      void put(K key, V value)
      Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Throws:
      NullArgumentException - key or value is null
      UnsupportedException - map is not modifiable
    • putAll

      void putAll(K key, Collection<? extends V> values)
      Adds a collection of values to to a key in this map
      Parameters:
      key - the key
      values - the values
      Throws:
      NullArgumentException - key or values is null
      UnsupportedException - map is not modifiable
    • putAll

      void putAll(Map<K, Collection<? extends V>> map)
      Stores a map of keys and values inside this map.
      Parameters:
      map - the map to store
      Throws:
      NullArgumentException - map is null
      UnsupportedException - map is not modifiable
    • putAll

      void putAll(MultiMap<K, ? extends V> map)
      Stores a Multimap inside this map.
      Parameters:
      map - the map to store
      Throws:
      NullArgumentException - map is null
      UnsupportedException - map is not modifiable
    • remove

      void remove(K key)
      Removes the mapping for a key and all its related values.
      Parameters:
      key - whose mapping is to be removed from the map
      Throws:
      NullArgumentException - key is null
      UnsupportedException - map is not modifiable
    • remove

      void remove(K key, V value)
      Removes a specific key/value pair from the map. The item is removed from the collection mapped to the specified key. Other values attached to that key are unaffected.
      Parameters:
      key - the key
      value - the value to remove
      Throws:
      NullArgumentException - key or value is null
      UnsupportedException - map is not modifiable
    • removeValue

      void removeValue(V value)
      Removes a value.
      Parameters:
      value - to be removed from the map
      Throws:
      NullArgumentException - value is null
    • clear

      void clear()
      Removes all of the mappings from this map. The map will be empty after this call returns.
      Throws:
      UnsupportedException - map is not modifiable
    • keySet

      Collection<K> keySet()
      Returns an immutable Collection view of the keys contained in this map.
      Returns:
      a set view of the keys contained in this map
    • values

      Collection<V> values()
      Returns a Collection view of the values contained in this map.
      Returns:
      a collection of the values
    • asMap

      Map<K, Collection<V>> asMap()
      Gets a Map of this MultiMap.
      Returns:
      a map view of this MultiMap