Class AbstractSetMultimap<K,V>
- All Implemented Interfaces:
Multimap<K,,V> SetMultimap<K,,V> Serializable
- Direct Known Subclasses:
AbstractSortedSetMultimap,HashMultimapGwtSerializationDependencies,LinkedHashMultimapGwtSerializationDependencies,Multimaps.CustomSetMultimap
SetMultimap interface. It's a wrapper around AbstractMapBasedMultimap that converts the returned collections into Sets. The createCollection() method must return a Set.-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.common.collect.AbstractMapBasedMultimap
AbstractMapBasedMultimap.NavigableAsMap, AbstractMapBasedMultimap.NavigableKeySet, AbstractMapBasedMultimap.WrappedCollection, AbstractMapBasedMultimap.WrappedList, AbstractMapBasedMultimap.WrappedNavigableSet, AbstractMapBasedMultimap.WrappedSet, AbstractMapBasedMultimap.WrappedSortedSetNested classes/interfaces inherited from class com.google.common.collect.AbstractMultimap
AbstractMultimap.Entries, AbstractMultimap.EntrySet, AbstractMultimap.Values -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSetMultimap(Map<K, Collection<V>> map) Creates a new multimap that uses the provided map. -
Method Summary
Modifier and TypeMethodDescriptionMap<K,Collection<V>> asMap()Returns a view of this multimap as aMapfrom each distinct key to the nonempty collection of that key's associated values.Creates the collection of values for a single key.Creates an unmodifiable, empty collection of values.entries()Returns a view collection of all key-value pairs contained in this multimap, asMap.Entryinstances.booleanCompares the specified object to this multimap for equality.Returns a view collection of the values associated withkeyin this multimap, if any.booleanStores a key-value pair in the multimap.Removes all values associated with the keykey.replaceValues(K key, Iterable<? extends V> values) Stores a collection of values with the same key, replacing any existing values for that key.(package private) <E> Collection<E>unmodifiableCollectionSubclass(Collection<E> collection) (package private) Collection<V>wrapCollection(K key, Collection<V> collection) Generates a decorated collection that remains consistent with the values in the multimap for the provided key.Methods inherited from class com.google.common.collect.AbstractMapBasedMultimap
backingMap, clear, containsKey, createAsMap, createCollection, createEntries, createKeys, createKeySet, createMaybeNavigableAsMap, createMaybeNavigableKeySet, createValues, entryIterator, entrySpliterator, forEach, setMap, size, valueIterator, values, valueSpliterator, wrapListMethods inherited from class com.google.common.collect.AbstractMultimap
containsEntry, containsValue, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.google.common.collect.Multimap
clear, containsEntry, containsKey, containsValue, forEach, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, size, values
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
AbstractSetMultimap
Creates a new multimap that uses the provided map.- Parameters:
map- place to store the mapping from each key to its corresponding values
-
-
Method Details
-
createCollection
Description copied from class:AbstractMapBasedMultimapCreates the collection of values for a single key.Collections with weak, soft, or phantom references are not supported. Each call to
createCollectionshould create a new instance.The returned collection class determines whether duplicate key-value pairs are allowed.
- Specified by:
createCollectionin classAbstractMapBasedMultimap<K,V> - Returns:
- an empty collection of values
-
createUnmodifiableEmptyCollection
Description copied from class:AbstractMapBasedMultimapCreates an unmodifiable, empty collection of values.This is used in
AbstractMapBasedMultimap.removeAll(java.lang.Object)on an empty key.- Overrides:
createUnmodifiableEmptyCollectionin classAbstractMapBasedMultimap<K,V>
-
unmodifiableCollectionSubclass
- Overrides:
unmodifiableCollectionSubclassin classAbstractMapBasedMultimap<K,V>
-
wrapCollection
Description copied from class:AbstractMapBasedMultimapGenerates a decorated collection that remains consistent with the values in the multimap for the provided key. Changes to the multimap may alter the returned collection, and vice versa.- Overrides:
wrapCollectionin classAbstractMapBasedMultimap<K,V>
-
get
Returns a view collection of the values associated withkeyin this multimap, if any. Note that whencontainsKey(key)is false, this returns an empty collection, notnull.Changes to the returned collection will update the underlying multimap, and vice versa.
The returned collection is not serializable.
Because a
SetMultimaphas unique values for a given key, this method returns aSet, instead of theCollectionspecified in theMultimapinterface. -
entries
Returns a view collection of all key-value pairs contained in this multimap, asMap.Entryinstances.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
SetMultimaphas unique values for a given key, this method returns aSet, instead of theCollectionspecified in theMultimapinterface. -
removeAll
Removes all values associated with the keykey.Once this method returns,
keywill not be mapped to any values, so it will not appear inMultimap.keySet(),Multimap.asMap(), or any other views.The returned collection is immutable.
Because a
SetMultimaphas unique values for a given key, this method returns aSet, instead of theCollectionspecified in theMultimapinterface.- Specified by:
removeAllin interfaceMultimap<K,V> - Specified by:
removeAllin interfaceSetMultimap<K,V> - Overrides:
removeAllin classAbstractMapBasedMultimap<K,V> - Returns:
- the values that were removed (possibly empty). The returned collection may be modifiable, but updating it will have no effect on the multimap.
-
replaceValues
Stores a collection of values with the same key, replacing any existing values for that key.If
valuesis empty, this is equivalent toremoveAll(key).The returned collection is immutable.
Because a
SetMultimaphas unique values for a given key, this method returns aSet, instead of theCollectionspecified in theMultimapinterface.Any duplicates in
valueswill be stored in the multimap once.- Specified by:
replaceValuesin interfaceMultimap<K,V> - Specified by:
replaceValuesin interfaceSetMultimap<K,V> - Overrides:
replaceValuesin classAbstractMapBasedMultimap<K,V> - Returns:
- the collection of replaced values, or an empty collection if no values were previously associated with the key. The collection may be modifiable, but updating it will have no effect on the multimap.
-
asMap
Returns a view of this multimap as aMapfrom each distinct key to the nonempty collection of that key's associated values. Note thatthis.asMap().get(k)is equivalent tothis.get(k)only whenkis a key contained in the multimap; otherwise it returnsnullas 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
putorputAll, nor do its entries supportsetValue.Though the method signature doesn't say so explicitly, the returned map has
Setvalues. -
put
Stores a key-value pair in the multimap.- Specified by:
putin interfaceMultimap<K,V> - Overrides:
putin classAbstractMapBasedMultimap<K,V> - Parameters:
key- key to store in the multimapvalue- value to store in the multimap- Returns:
trueif the method increased the size of the multimap, orfalseif the multimap already contained the key-value pair
-
equals
Compares the specified object to this multimap for equality.Two
SetMultimapinstances are equal if, for each key, they contain the same values. Equality does not depend on the ordering of keys or values.
-