Module me.sbasalaev.common
Package me.sbasalaev.collection
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
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 -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a shallow copy of this multimap.Associations between keys and collections of values in this multimap.booleancontainsEntry(Object key, Object value) Whether given key corresponds to given value in this map.booleancontainsEntry(Entry<K, ?> entry) Whether given key corresponds to given value in this map.booleancontainsKey(Object key) Whether given key is present in this map.abstract Traversable<Entry<K, V>> entries()All key-value associations of this multimap.abstract booleanWhether given object is equal to this multimap.abstract CCollection of values associated with given key in this multimap.inthashCode()Hash code of the multimap.booleanisEmpty()Whether this multimap has no entries.keys()Set of keys that have at least one associated value in this multimap.abstract intkeySize()Number of keys in this multimap that have at least one associated value.booleannonEmpty()Whether this multimap has at least one entry.intsize()Number of key-value pairs in this multimap.toString()String representation of this map.values()Traverses all the values of this multimap.
-
Constructor Details
-
Multimap
public Multimap()Constructor for subclasses.
-
-
Method Details
-
get
Collection of values associated with given key in this multimap. -
containsKey
Whether given key is present in this map. -
containsEntry
Whether given key corresponds to given value in this map. -
containsEntry
Whether given key corresponds to given value in this map. -
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
Associations between keys and collections of values in this multimap. -
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
Traverses all the values of this multimap. -
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. -
equals
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 ofcollectionEntries()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. -
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. -
toString
String representation of this map. The returned string has the same format as the string for the entries set.
-