@GwtCompatible(serializable=true, emulated=true) public final class HashMultimap<K,V> extends AbstractSetMultimap<K,V>
Multimap
using 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>)
.
AbstractMapBasedMultimap.NavigableAsMap, AbstractMapBasedMultimap.NavigableKeySet, AbstractMapBasedMultimap.WrappedNavigableSet
AbstractMultimap.Values
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_VALUES_PER_KEY |
(package private) int |
expectedValuesPerKey |
private static long |
serialVersionUID |
Modifier | Constructor and Description |
---|---|
private |
HashMultimap() |
private |
HashMultimap(int expectedKeys,
int expectedValuesPerKey) |
private |
HashMultimap(Multimap<? extends K,? extends V> multimap) |
Modifier and Type | Method and Description |
---|---|
static <K,V> HashMultimap<K,V> |
create()
Creates a new, empty
HashMultimap with the default initial
capacities. |
static <K,V> HashMultimap<K,V> |
create(int expectedKeys,
int expectedValuesPerKey)
Constructs an empty
HashMultimap with 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 a
HashMultimap with the same mappings as the specified
multimap. |
(package private) java.util.Set<V> |
createCollection()
Creates the collection of values for a single key.
|
private void |
readObject(java.io.ObjectInputStream stream) |
private void |
writeObject(java.io.ObjectOutputStream stream) |
asMap, createUnmodifiableEmptyCollection, entries, equals, get, put, removeAll, replaceValues
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 int DEFAULT_VALUES_PER_KEY
transient int expectedValuesPerKey
@GwtIncompatible(value="Not needed in emulated source") private static final long serialVersionUID
private HashMultimap()
private HashMultimap(int expectedKeys, int expectedValuesPerKey)
public static <K,V> HashMultimap<K,V> create()
HashMultimap
with the default initial
capacities.public static <K,V> HashMultimap<K,V> create(int expectedKeys, int expectedValuesPerKey)
HashMultimap
with enough capacity to hold the
specified numbers of keys and values without rehashing.expectedKeys
- the expected number of distinct keysexpectedValuesPerKey
- the expected average number of values per keyjava.lang.IllegalArgumentException
- if expectedKeys
or expectedValuesPerKey
is negativepublic static <K,V> HashMultimap<K,V> create(Multimap<? extends K,? extends V> multimap)
HashMultimap
with 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.multimap
- the multimap whose contents are copied to this multimapjava.util.Set<V> createCollection()
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.
Creates an empty HashSet
for a collection of values for one key.
createCollection
in class AbstractSetMultimap<K,V>
HashSet
containing a collection of values for one key@GwtIncompatible(value="java.io.ObjectOutputStream") private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException
java.io.IOException
@GwtIncompatible(value="java.io.ObjectInputStream") private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException