Class HashMultimap<K,V>
- java.lang.Object
-
- com.google.common.collect.AbstractMultimap<K,V>
-
- com.google.common.collect.AbstractMapBasedMultimap<K,V>
-
- com.google.common.collect.AbstractSetMultimap<K,V>
-
- com.google.common.collect.HashMultimapGwtSerializationDependencies<K,V>
-
- com.google.common.collect.HashMultimap<K,V>
-
- All Implemented Interfaces:
Multimap<K,V>,SetMultimap<K,V>,java.io.Serializable
@GwtCompatible(serializable=true, emulated=true) public final class HashMultimap<K,V> extends HashMultimapGwtSerializationDependencies<K,V>
Implementation ofMultimapusing hash tables.The multimap does not store duplicate key-value pairs. Adding a new key-value pair equal to an existing key-value pair has no effect.
Keys and values may be null. All optional multimap methods are supported, and all returned views are modifiable.
This class is not threadsafe when any concurrent operations update the multimap. Concurrent read operations will work correctly. To allow concurrent update operations, wrap your multimap with a call to
Multimaps.synchronizedSetMultimap(com.google.common.collect.SetMultimap<K, V>).- Since:
- 2.0
- See Also:
- Serialized Form
-
-
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 intDEFAULT_VALUES_PER_KEY(package private) intexpectedValuesPerKeyprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description privateHashMultimap()privateHashMultimap(int expectedKeys, int expectedValuesPerKey)privateHashMultimap(Multimap<? extends K,? extends V> multimap)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K,V>
HashMultimap<K,V>create()Creates a new, emptyHashMultimapwith the default initial capacities.static <K,V>
HashMultimap<K,V>create(int expectedKeys, int expectedValuesPerKey)Constructs an emptyHashMultimapwith enough capacity to hold the specified numbers of keys and values without rehashing.static <K,V>
HashMultimap<K,V>create(Multimap<? extends K,? extends V> multimap)Constructs aHashMultimapwith the same mappings as the specified multimap.(package private) java.util.Set<V>createCollection()Creates the collection of values for a single key.private voidreadObject(java.io.ObjectInputStream stream)private voidwriteObject(java.io.ObjectOutputStream stream)-
Methods inherited from class com.google.common.collect.AbstractSetMultimap
asMap, createUnmodifiableEmptyCollection, entries, equals, get, put, removeAll, replaceValues, unmodifiableCollectionSubclass, wrapCollection
-
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, wrapList
-
Methods inherited from class com.google.common.collect.AbstractMultimap
containsEntry, containsValue, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.collect.Multimap
clear, containsEntry, containsKey, containsValue, forEach, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, size, values
-
-
-
-
Field Detail
-
DEFAULT_VALUES_PER_KEY
private static final int DEFAULT_VALUES_PER_KEY
- See Also:
- Constant Field Values
-
expectedValuesPerKey
transient int expectedValuesPerKey
-
serialVersionUID
@GwtIncompatible private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static <K,V> HashMultimap<K,V> create()
Creates a new, emptyHashMultimapwith the default initial capacities.This method will soon be deprecated in favor of
MultimapBuilder.hashKeys().hashSetValues().build().
-
create
public static <K,V> HashMultimap<K,V> create(int expectedKeys, int expectedValuesPerKey)
Constructs an emptyHashMultimapwith enough capacity to hold the specified numbers of keys and values without rehashing.This method will soon be deprecated in favor of
MultimapBuilder.hashKeys(expectedKeys).hashSetValues(expectedValuesPerKey).build().- Parameters:
expectedKeys- the expected number of distinct keysexpectedValuesPerKey- the expected average number of values per key- Throws:
java.lang.IllegalArgumentException- ifexpectedKeysorexpectedValuesPerKeyis negative
-
create
public static <K,V> HashMultimap<K,V> create(Multimap<? extends K,? extends V> multimap)
Constructs aHashMultimapwith the same mappings as the specified multimap. If a key-value mapping appears multiple times in the input multimap, it only appears once in the constructed multimap.This method will soon be deprecated in favor of
MultimapBuilder.hashKeys().hashSetValues().build(multimap).- Parameters:
multimap- the multimap whose contents are copied to this multimap
-
createCollection
java.util.Set<V> createCollection()
Creates 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.
Creates an empty
HashSetfor a collection of values for one key.- Specified by:
createCollectionin classAbstractSetMultimap<K,V>- Returns:
- a new
HashSetcontaining a collection of values for one key
-
writeObject
@GwtIncompatible private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException
- Throws:
java.io.IOException
-
readObject
@GwtIncompatible private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-