Interface Multimap<K,V>

Type Parameters:
K - The key
V - The value
All Known Implementing Classes:
ListMultimap, SetMultimap

public interface Multimap<K,V>
A collection-like structure that maps keys to collections of values.
Author:
Martin Kouba
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all of the mappings.
    boolean
     
    Map.Entry.getValue() always returns an unmodifiable collection.
    get(K key)
    This method never returns null.
    boolean
     
     
    boolean
    put(K key, V value)
     
    boolean
    putAll(K key, Collection<? extends V> values)
     
    replaceValues(K key, Iterable<? extends V> values)
    Note that the original collection of values is completely replaced by a new collection which contains all elements from the given iterable.
    int
    Unlike Guava'sMultimap#size() this method returns the number of key-value mappings.
     
    The list may include the same value multiple times if it occurs in multiple mappings or if the collection of values for the mapping allows duplicate elements.
  • Method Details

    • size

      int size()
      Unlike Guava'sMultimap#size() this method returns the number of key-value mappings.
      Returns:
      the number of key-value mappings
    • isEmpty

      boolean isEmpty()
      Returns:
      true if there are no key-value mappings
    • get

      Collection<V> get(K key)
      This method never returns null. If no collection of values for a given key exists a new value collection is initialized.
      Parameters:
      key -
      Returns:
      the collection of values for the given key
    • put

      boolean put(K key, V value)
      Parameters:
      key -
      value -
      Returns:
      true if the the size of the collection associated with the given key increased, false otherwise (e.g. if the collection of values doesn't allow duplicates)
    • putAll

      boolean putAll(K key, Collection<? extends V> values)
      Parameters:
      key -
      values -
      Returns:
      true if the the size of the collection associated with the given key increased, false otherwise (e.g. if the collection of values doesn't allow duplicates)
    • replaceValues

      Collection<V> replaceValues(K key, Iterable<? extends V> values)
      Note that the original collection of values is completely replaced by a new collection which contains all elements from the given iterable. If the collection of values doesn't allow duplicates, these elements are removed.
      Parameters:
      key -
      values -
      Returns:
      the collection of replaced values
    • containsKey

      boolean containsKey(Object key)
      Parameters:
      key -
      Returns:
      true if the multimap contains a mapping for the given key
    • keySet

      Set<K> keySet()
      Returns:
      an immutable set of keys
    • values

      List<V> values()
      The list may include the same value multiple times if it occurs in multiple mappings or if the collection of values for the mapping allows duplicate elements.
      Returns:
      an immutable list of all the values in the multimap
    • uniqueValues

      Set<V> uniqueValues()
      Returns:
      an immutable set of all the values in the multimap
    • entrySet

      Set<Map.Entry<K,Collection<V>>> entrySet()
      Map.Entry.getValue() always returns an unmodifiable collection. Map.Entry.setValue(Object) operation is not supported.
      Returns:
      an immutable set of all key-value pairs
    • clear

      void clear()
      Removes all of the mappings.