Class AbstractListMultimap<K,V>
- java.lang.Object
-
- com.google.common.collect.AbstractMultimap<K,V>
-
- com.google.common.collect.AbstractMapBasedMultimap<K,V>
-
- com.google.common.collect.AbstractListMultimap<K,V>
-
- All Implemented Interfaces:
ListMultimap<K,V>,Multimap<K,V>,java.io.Serializable
- Direct Known Subclasses:
ArrayListMultimapGwtSerializationDependencies,Multimaps.CustomListMultimap
abstract class AbstractListMultimap<K,V> extends AbstractMapBasedMultimap<K,V> implements ListMultimap<K,V>
Basic implementation of theListMultimapinterface. It's a wrapper aroundAbstractMapBasedMultimapthat converts the returned collections intoLists. ThecreateCollection()method must return aList.- Since:
- 2.0
-
-
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.WrappedSortedSet
-
Nested classes/interfaces inherited from class com.google.common.collect.AbstractMultimap
AbstractMultimap.Entries, AbstractMultimap.EntrySet, AbstractMultimap.Values
-
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractListMultimap(java.util.Map<K,java.util.Collection<V>> map)Creates a new multimap that uses the provided map.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.Map<K,java.util.Collection<V>>asMap()Returns a view of this multimap as aMapfrom each distinct key to the nonempty collection of that key's associated values.(package private) abstract java.util.List<V>createCollection()Creates the collection of values for a single key.(package private) java.util.List<V>createUnmodifiableEmptyCollection()Creates an unmodifiable, empty collection of values.booleanequals(java.lang.Object object)Compares the specified object to this multimap for equality.java.util.List<V>get(K key)Returns a view collection of the values associated withkeyin this multimap, if any.booleanput(K key, V value)Stores a key-value pair in the multimap.java.util.List<V>removeAll(java.lang.Object key)Removes all values associated with the keykey.java.util.List<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.(package private) <E> java.util.Collection<E>unmodifiableCollectionSubclass(java.util.Collection<E> collection)(package private) java.util.Collection<V>wrapCollection(K key, java.util.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, entries, entryIterator, entrySpliterator, forEach, setMap, size, valueIterator, values, valueSpliterator, wrapList
-
Methods inherited from class com.google.common.collect.AbstractMultimap
containsEntry, containsValue, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
createCollection
abstract java.util.List<V> 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
java.util.List<V> 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
<E> java.util.Collection<E> unmodifiableCollectionSubclass(java.util.Collection<E> collection)
- Overrides:
unmodifiableCollectionSubclassin classAbstractMapBasedMultimap<K,V>
-
wrapCollection
java.util.Collection<V> wrapCollection(K key, java.util.Collection<V> collection)
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
public java.util.List<V> get(K key)
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 the values for a given key may have duplicates and follow the insertion ordering, this method returns a
List, instead of theCollectionspecified in theMultimapinterface.
-
removeAll
public java.util.List<V> removeAll(java.lang.Object key)
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 the values for a given key may have duplicates and follow the insertion ordering, this method returns a
List, instead of theCollectionspecified in theMultimapinterface.- Specified by:
removeAllin interfaceListMultimap<K,V>- Specified by:
removeAllin interfaceMultimap<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
public java.util.List<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.If
valuesis empty, this is equivalent toremoveAll(key).The returned collection is immutable.
Because the values for a given key may have duplicates and follow the insertion ordering, this method returns a
List, instead of theCollectionspecified in theMultimapinterface.- Specified by:
replaceValuesin interfaceListMultimap<K,V>- Specified by:
replaceValuesin interfaceMultimap<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
public java.util.Map<K,java.util.Collection<V>> 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
Listvalues.
-
equals
public boolean equals(java.lang.Object object)
Compares the specified object to this multimap for equality.Two
ListMultimapinstances are equal if, for each key, they contain the same values in the same order. If the value orderings disagree, the multimaps will not be considered equal.
-
-