Class Multimap<K,V,C extends Collection<V>>

java.lang.Object
me.sbasalaev.collection.Multimap<K,V,C>
Type Parameters:
K - type of the keys of this multimap.
V - type of the values of this multimap.
C - type of the collections of values corresponding to a single key.
Direct Known Subclasses:
ListMultimap, Map, SetMultimap

public abstract class Multimap<K,@Out V,@Out C extends Collection<@Out V>> extends Object
Common superclass for maps and multimaps. Multimaps associate keys with collections of values. Map is a type of a multimap that associates key with at most one value, so a multimap of Opt collections. Every multimap has a notion of equality though that notion depends on the type of the collection of values. Multimap may be cloned to obtain a copy of a collection of the same type.
Since:
3.2
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for subclasses.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Multimap<K,V,C>
    Returns a shallow copy of this multimap.
    abstract Set<Entry<K,C>>
    Associations between keys and collections of values in this multimap.
    boolean
    Whether given key corresponds to given value in this map.
    boolean
    containsEntry(Entry<K,?> entry)
    Whether given key corresponds to given value in this map.
    boolean
    Whether given key is present in this map.
    abstract Traversable<Entry<K,V>>
    All key-value associations of this multimap.
    abstract boolean
    Whether given object is equal to this multimap.
    abstract C
    get(Object key)
    Collection of values associated with given key in this multimap.
    int
    Hash code of the multimap.
    boolean
    Whether this multimap has no entries.
    Set of keys that have at least one associated value in this multimap.
    abstract int
    Number of keys in this multimap that have at least one associated value.
    boolean
    Whether this multimap has at least one entry.
    int
    Number of key-value pairs in this multimap.
    String representation of this map.
    Traverses all the values of this multimap.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Multimap

      public Multimap()
      Constructor for subclasses.
  • Method Details

    • get

      public abstract C get(Object key)
      Collection of values associated with given key in this multimap.
    • containsKey

      public boolean containsKey(Object key)
      Whether given key is present in this map.
    • containsEntry

      public boolean containsEntry(Entry<K,?> entry)
      Whether given key corresponds to given value in this map.
    • containsEntry

      public boolean containsEntry(Object key, Object value)
      Whether given key corresponds to given value in this map.
    • entries

      public abstract Traversable<Entry<K,V>> entries()
      All key-value associations of this multimap. If this multimap allows multiple value associations to the single key (like e. g. ListMultimap) then the same entry is returned multiple times.
    • collectionEntries

      public abstract Set<Entry<K,C>> collectionEntries()
      Associations between keys and collections of values in this multimap.
    • keys

      public Set<K> keys()
      Set of keys that have at least one associated value in this multimap.
    • keySize

      public abstract int keySize()
      Number of keys in this multimap that have at least one associated value.
    • size

      public int size()
      Number of key-value pairs in this multimap.
    • isEmpty

      public boolean isEmpty()
      Whether this multimap has no entries.
    • nonEmpty

      public boolean nonEmpty()
      Whether this multimap has at least one entry.
    • values

      public Traversable<V> values()
      Traverses all the values of this multimap.
    • clone

      public abstract Multimap<K,V,C> clone()
      Returns a shallow copy of this multimap. The returned multimap is immutable, has the same type and contains the same collections of elements. The multimap is allowed to return itself if it is immutable.
      Overrides:
      clone in class Object
    • equals

      public abstract boolean equals(@Nullable Object obj)
      Whether given object is equal to this multimap. Multimaps are equal if they map keys to the same collection types of values and the sets of collectionEntries() are the same. Multimaps of different collection types are not equal to each other. In particular empty multimaps of different types are unequal since they return unequal empty collections.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Hash code of the multimap. The hash code of the multimap is defined as a sum of hash codes of all its entries.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      String representation of this map. The returned string has the same format as the string for the entries set.
      Overrides:
      toString in class Object