Top Description Fields Constructors Methods
com.google.common.collect

public final Class HashMultimap<K extends @Nullable Object, V extends @Nullable Object>

extends HashMultimapGwtSerializationDependencies<K extends @Nullable Object, V extends @Nullable Object>
Class Inheritance
Annotations
@GwtCompatible
serializable:true
emulated:true
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, .GwtIncompatible, .J2ktIncompatible, .VisibleForTesting, com.google.common.base.Preconditions, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, java.util.Collection, .Map, .Set, org.checkerframework.checker.nullness.qual.Nullable

Implementation of 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 if the last write happens-before any reads. To allow concurrent update operations, wrap your multimap with a call to Multimaps#synchronizedSetMultimap.

Warning

Do not modify either a key or a value of a HashMultimap in a way that affects its Object#equals behavior. Undefined behavior and bugs will result.

Author
Jared Levy
Since
2.0

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv transient int
private static final long

Constructor Summary

AccessConstructor and Description
private
private
HashMultimap(int expectedKeys, int expectedValuesPerKey)

private
HashMultimap(Multimap<? extends K, ? extends V> multimap)

Method Summary

Modifier and TypeMethod and Description
public static <K extends @Nullable Object, V extends @Nullable Object> HashMultimap<K, V>
create()

Creates a new, empty HashMultimap with the default initial capacities.

public static <K extends @Nullable Object, V extends @Nullable Object> HashMultimap<K, V>
create(int
the expected number of distinct keys
expectedKeys
,
int
the expected average number of values per key
expectedValuesPerKey
)

Constructs an empty HashMultimap with enough capacity to hold the specified numbers of keys and values without rehashing.

public static <K extends @Nullable Object, V extends @Nullable Object> HashMultimap<K, V>
create(Multimap<? extends K, ? extends V>
the multimap whose contents are copied to this multimap
multimap
)

Constructs a HashMultimap with the same mappings as the specified multimap.

pack-priv Set<V>

Returns:

a new HashSet containing a collection of values for one key
createCollection
()

Implements abstract com.google.common.collect.AbstractSetMultimap.createCollection.

Creates the collection of values for a single key.
private void
private void

Field Detail

DEFAULT_VALUES_PER_KEYback to summary
private static final int DEFAULT_VALUES_PER_KEY
expectedValuesPerKeyback to summary
pack-priv transient int expectedValuesPerKey
Annotations
@VisibleForTesting
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.google.common.collect.AbstractSetMultimap.serialVersionUID.

Annotations
@GwtIncompatible
@J2ktIncompatible

Constructor Detail

HashMultimapback to summary
private HashMultimap()
HashMultimapback to summary
private HashMultimap(int expectedKeys, int expectedValuesPerKey)
HashMultimapback to summary
private HashMultimap(Multimap<? extends K, ? extends V> multimap)

Method Detail

createback to summary
public static <K extends @Nullable Object, V extends @Nullable Object> HashMultimap<K, V> create()

Creates a new, empty HashMultimap with the default initial capacities.

This method will soon be deprecated in favor of MultimapBuilder.hashKeys().hashSetValues().build().

createback to summary
public static <K extends @Nullable Object, V extends @Nullable Object> 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.

This method will soon be deprecated in favor of MultimapBuilder.hashKeys(expectedKeys).hashSetValues(expectedValuesPerKey).build().

Parameters
expectedKeys:int

the expected number of distinct keys

expectedValuesPerKey:int

the expected average number of values per key

Exceptions
IllegalArgumentException:
if expectedKeys or expectedValuesPerKey is negative
createback to summary
public static <K extends @Nullable Object, V extends @Nullable Object> HashMultimap<K, V> create(Multimap<? extends K, ? extends V> multimap)

Constructs a 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.

This method will soon be deprecated in favor of MultimapBuilder.hashKeys().hashSetValues().build(multimap).

Parameters
multimap:Multimap<? extends K, ? extends V>

the multimap whose contents are copied to this multimap

createCollectionback to summary
pack-priv Set<V> createCollection()

Implements abstract com.google.common.collect.AbstractSetMultimap.createCollection.

Doc from com.google.common.collect.AbstractMapBasedMultimap.createCollection.

Creates the collection of values for a single key.

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.

Returns:Set<V>

a new HashSet containing a collection of values for one key

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
Annotations
@GwtIncompatible
@J2ktIncompatible
writeObjectback to summary
private void writeObject(ObjectOutputStream stream) throws IOException
Annotations
@GwtIncompatible
@J2ktIncompatible
Serial data
expectedValuesPerKey, number of distinct keys, and then for each distinct key: the key, number of values for that key, and the key's values