@GwtCompatible abstract class AbstractSetMultimap<K,V> extends AbstractMapBasedMultimap<K,V> implements SetMultimap<K,V>
SetMultimap
interface. It's a wrapper
around AbstractMapBasedMultimap
that converts the returned collections into
Sets
. The createCollection()
method must return a Set
.AbstractMapBasedMultimap.NavigableAsMap, AbstractMapBasedMultimap.NavigableKeySet, AbstractMapBasedMultimap.WrappedNavigableSet
AbstractMultimap.Values
Modifier and Type | Field and Description |
---|---|
private static long |
serialVersionUID |
Modifier | Constructor and Description |
---|---|
protected |
AbstractSetMultimap(java.util.Map<K,java.util.Collection<V>> map)
Creates a new multimap that uses the provided map.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<K,java.util.Collection<V>> |
asMap()
Returns a view of this multimap as a
Map from each distinct key
to the nonempty collection of that key's associated values. |
(package private) abstract java.util.Set<V> |
createCollection()
Creates the collection of values for a single key.
|
(package private) java.util.Set<V> |
createUnmodifiableEmptyCollection()
Creates an unmodifiable, empty collection of values.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entries()
Returns a view collection of all key-value pairs contained in this
multimap, as
Map.Entry instances. |
boolean |
equals(java.lang.Object object)
Compares the specified object to this multimap for equality.
|
java.util.Set<V> |
get(K key)
Returns a view collection of the values associated with
key in this
multimap, if any. |
boolean |
put(K key,
V value)
Stores a key-value pair in the multimap.
|
java.util.Set<V> |
removeAll(java.lang.Object key)
Removes all values associated with the key
key . |
java.util.Set<V> |
replaceValues(K key,
java.lang.Iterable<? extends V> values)
Stores a collection of values with the same key, replacing any existing
values for that key.
|
backingMap, clear, containsKey, createAsMap, createCollection, createKeySet, entryIterator, setMap, size, unmodifiableCollectionSubclass, valueIterator, values, wrapCollection
containsEntry, containsValue, createEntries, createKeys, createValues, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
clear, containsEntry, containsKey, containsValue, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, size, values
private static final long serialVersionUID
abstract java.util.Set<V> createCollection()
AbstractMapBasedMultimap
Collections with weak, soft, or phantom references are not supported.
Each call to createCollection
should create a new instance.
The returned collection class determines whether duplicate key-value pairs are allowed.
createCollection
in class AbstractMapBasedMultimap<K,V>
java.util.Set<V> createUnmodifiableEmptyCollection()
AbstractMapBasedMultimap
This is used in AbstractMapBasedMultimap.removeAll(java.lang.Object)
on an empty key.
createUnmodifiableEmptyCollection
in class AbstractMapBasedMultimap<K,V>
public java.util.Set<V> get(@Nullable K key)
key
in this
multimap, if any. Note that when containsKey(key)
is false, this
returns an empty collection, not null
.
Changes to the returned collection will update the underlying multimap, and vice versa.
The returned collection is not serializable.
Because a SetMultimap
has unique values for a given key, this
method returns a Set
, instead of the Collection
specified
in the Multimap
interface.
public java.util.Set<java.util.Map.Entry<K,V>> entries()
Map.Entry
instances.
Changes to the returned collection or the entries it contains will update the underlying multimap, and vice versa. However, adding to the returned collection is not possible.
The iterator generated by the returned collection traverses the values for one key, followed by the values of a second key, and so on.
Each entry is an immutable snapshot of a key-value mapping in the multimap, taken at the time the entry is returned by a method call to the collection or its iterator.
Because a SetMultimap
has unique values for a given key, this
method returns a Set
, instead of the Collection
specified
in the Multimap
interface.
public java.util.Set<V> removeAll(@Nullable java.lang.Object key)
key
.
Once this method returns, key
will not be mapped to any values,
so it will not appear in Multimap.keySet()
, Multimap.asMap()
, or any other
views.
The returned collection is immutable.
Because a SetMultimap
has unique values for a given key, this
method returns a Set
, instead of the Collection
specified
in the Multimap
interface.
removeAll
in interface Multimap<K,V>
removeAll
in interface SetMultimap<K,V>
removeAll
in class AbstractMapBasedMultimap<K,V>
public java.util.Set<V> replaceValues(@Nullable K key, java.lang.Iterable<? extends V> values)
If values
is empty, this is equivalent to
removeAll(key)
.
The returned collection is immutable.
Because a SetMultimap
has unique values for a given key, this
method returns a Set
, instead of the Collection
specified
in the Multimap
interface.
Any duplicates in values
will be stored in the multimap once.
replaceValues
in interface Multimap<K,V>
replaceValues
in interface SetMultimap<K,V>
replaceValues
in class AbstractMapBasedMultimap<K,V>
public java.util.Map<K,java.util.Collection<V>> asMap()
Map
from each distinct key
to the nonempty collection of that key's associated values. Note that
this.asMap().get(k)
is equivalent to this.get(k)
only when
k
is a key contained in the multimap; otherwise it returns null
as opposed to an empty collection.
Changes to the returned map or the collections that serve as its values
will update the underlying multimap, and vice versa. The map does not
support put
or putAll
, nor do its entries support setValue
.
Though the method signature doesn't say so explicitly, the returned map
has Set
values.
public boolean put(@Nullable K key, @Nullable V value)
put
in interface Multimap<K,V>
put
in class AbstractMapBasedMultimap<K,V>
key
- key to store in the multimapvalue
- value to store in the multimaptrue
if the method increased the size of the multimap, or
false
if the multimap already contained the key-value pairpublic boolean equals(@Nullable java.lang.Object object)
Two SetMultimap
instances are equal if, for each key, they
contain the same values. Equality does not depend on the ordering of keys
or values.