Class HashSetMultimap<K,V>
java.lang.Object
be.imgn.gaia.core.collect.HashSetMultimap<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
Multimap<K,V>, SetMultimap<K, V>, Serializable
A modifiable set multimap backed by a
HashMap from each key to a HashSet of its values. Its
keys and values must have consistent equals and hashCode methods.
- It iterates over its keys, and over the values of a key, in no particular order.
- It rejects
nullkeys and values, but querying it withnull, as incontainsKey(null), is allowed. - Its views are live, and its iterators support
Iterator.remove(). The collections ofMultimap.asMap()do not support adding values: add them throughMultimap.get(Object)orMultimap.put(K, V). - Its iterators fail fast, on a best-effort basis, when it changes while they iterate, outside of their own
remove(). - It is serializable if all its keys and values are.
- It is not thread-safe.
- Since:
- 0.1.2
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns a live view of this multimap as a map from each key to its values.voidclear()Removes all entries.booleancontainsEntry(@Nullable Object key, @Nullable Object value) Returns whether a key has a value.booleancontainsKey(@Nullable Object key) Returns whether a key has at least one value.booleancontainsValue(@Nullable Object value) Returns whether a value belongs to at least one key.static <K,V> HashSetMultimap <K, V> create()Returns a new, empty multimap.static <K,V> HashSetMultimap <K, V> Returns a new multimap containing the entries of another multimap.entries()Returns a live view of the entries, grouped by key.booleanReturns whether another object is a multimap with the same keys and values.voidforEach(BiConsumer<? super K, ? super V> action) Calls an action with the key and value of each entry, grouped by key.Returns a live view of the values of a key, empty if the key is absent.inthashCode()Returns the hash code ofMultimap.asMap().booleanisEmpty()Returns whether this multimap has no entries.keySet()Returns a live view of the distinct keys.booleanAdds an entry.booleanAdds the entries of another multimap.booleanAdds an entry for each of the given values, with the same key.booleanRemoves an entry.Removes all the values of a key.replaceValues(K key, Iterable<? extends V> values) Replaces all the values of a key.intsize()Returns the number of entries: the key-value pairs, not the distinct keys.toString()values()Returns a live view of the values of all keys, each value as many times as it occurs, grouped by key.Methods inherited from interface Multimap
clear, containsEntry, containsKey, containsValue, equals, forEach, hashCode, isEmpty, keySet, put, putAll, putAll, remove, size, valuesMethods inherited from interface SetMultimap
asMap, get, removeAll, replaceValues
-
Method Details
-
create
Returns a new, empty multimap.- Type Parameters:
K- the key typeV- the value type- Returns:
- a new, empty multimap
-
create
Returns a new multimap containing the entries of another multimap.- Type Parameters:
K- the key typeV- the value type- Parameters:
multimap- the multimap whose entries to add- Returns:
- a new multimap containing the entries of
multimap
-
entries
Description copied from interface:MultimapReturns a live view of the entries, grouped by key. The entries do not supportMap.Entry.setValue(V).- Specified by:
entriesin interfaceMultimap<K,V> - Specified by:
entriesin interfaceSetMultimap<K,V> - Returns:
- the entries of this multimap
-
size
public int size()Description copied from interface:MultimapReturns the number of entries: the key-value pairs, not the distinct keys.- Specified by:
sizein interfaceMultimap<K,V> - Returns:
- the number of entries, or
Integer.MAX_VALUEif there are more
-
isEmpty
-
containsKey
Description copied from interface:MultimapReturns whether a key has at least one value.- Specified by:
containsKeyin interfaceMultimap<K,V> - Parameters:
key- the key to look for- Returns:
trueif this multimap containskey
-
containsValue
Description copied from interface:MultimapReturns whether a value belongs to at least one key.- Specified by:
containsValuein interfaceMultimap<K,V> - Parameters:
value- the value to look for- Returns:
trueif this multimap containsvalue
-
containsEntry
Description copied from interface:MultimapReturns whether a key has a value.- Specified by:
containsEntryin interfaceMultimap<K,V> - Parameters:
key- the key to look forvalue- the value to look for- Returns:
trueif this multimap contains an entry withkeyandvalue
-
get
Description copied from interface:MultimapReturns a live view of the values of a key, empty if the key is absent. Adding to the view adds entries to this multimap, the key included if it was absent. -
keySet
-
values
Description copied from interface:MultimapReturns a live view of the values of all keys, each value as many times as it occurs, grouped by key. -
asMap
Description copied from interface:MultimapReturns a live view of this multimap as a map from each key to its values. The map and its collections support removal, but notputnor adding values. -
forEach
-
put
-
putAll
-
putAll
-
remove
Description copied from interface:MultimapRemoves an entry. AListMultimapremoves its first occurrence. -
removeAll
-
replaceValues
Description copied from interface:MultimapReplaces all the values of a key. Replacing them with no values removes the key.- Specified by:
replaceValuesin interfaceMultimap<K,V> - Parameters:
key- the keyvalues- the new values ofkey- Returns:
- the values replaced, in an unmodifiable collection, empty if the key was absent
-
clear
-
equals
Description copied from interface:MultimapReturns whether another object is a multimap with the same keys and values. Two multimaps are equal when theirMultimap.asMap()views are, so aListMultimapequals another one with the same values in the same order, and aSetMultimapanother one with the same values in any order. A list multimap never equals a set multimap, unless both are empty. -
hashCode
-
toString
-