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

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

extends LinkedHashMultimapGwtSerializationDependencies<K extends @Nullable Object, V extends @Nullable Object>
Class Inheritance
Annotations
@GwtCompatible
serializable:true
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, .Preconditions.checkState, com.google.common.collect.CollectPreconditions.checkNonnegative, java.util.Objects.requireNonNull

Implementation of Multimap that does not allow duplicate key-value entries and that returns collections whose iterators follow the ordering in which the data was added to the multimap.

The collections returned by keySet, keys, and asMap iterate through the keys in the order they were first added to the multimap. Similarly, get, removeAll, and replaceValues return collections that iterate through the values in the order they were added. The collections generated by entries and values iterate across the key-value mappings in the order they were added to the multimap.

The iteration ordering of the collections generated by keySet, keys, and asMap has a few subtleties. As long as the set of keys remains unchanged, adding or removing mappings does not affect the key iteration order. However, if you remove all values associated with a key and then add the key back to the multimap, that key will come last in the key iteration order.

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.

Warning

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

See the Guava User Guide article on Multimap.

Authors
Jared Levy, Louis Wasserman
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
LinkedHashMultimap.ValueEntry<K extends @Nullable Object, V extends @Nullable Object>

LinkedHashMultimap entries are in no less than three coexisting linked lists: a bucket in the hash table for a Set<V> associated with a key, the linked list of insertion-ordered entries in that Set<V>, and the linked list of entries in the LinkedHashMultimap as a whole.

pack-priv class
private static interface

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private transient LinkedHashMultimap.ValueEntry<K, V>
private static final long
pack-priv static final double
pack-priv transient int

Constructor Summary

AccessConstructor and Description
private
LinkedHashMultimap(int keyCapacity, int valueSetCapacity)

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides com.google.common.collect.AbstractMapBasedMultimap.clear.

Implements com.google.common.collect.Multimap.clear.

Removes all key-value pairs from the multimap, leaving it empty.
public static <K extends @Nullable Object, V extends @Nullable Object> LinkedHashMultimap<K, V>
create()

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

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

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

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

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

pack-priv Set<V>

Returns:

a new LinkedHashSet 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.
pack-priv Collection<V>

Returns:

a new decorated set containing a collection of values for one key
createCollection
(K
key to associate with values in the collection
key
)

Overrides com.google.common.collect.AbstractMapBasedMultimap.createCollection.

Creates the collection of values for an explicitly provided key.
private static <K extends @Nullable Object, V extends @Nullable Object> void
public Set<Map.Entry<K, V>>
pack-priv Iterator<Map.Entry<K, V>>
entryIterator()

Overrides com.google.common.collect.AbstractMapBasedMultimap.entryIterator.

Returns an iterator across all key-value map entries, used by entries().iterator() and values().iterator().
pack-priv Spliterator<Map.Entry<K, V>>
public Set<K>
keySet()

Overrides com.google.common.collect.AbstractMultimap.keySet.

Implements com.google.common.collect.Multimap.keySet.

Returns a view collection of all distinct keys contained in this multimap.
private void
public Set<V>
replaceValues(K key, Iterable<? extends V> values)

Overrides com.google.common.collect.AbstractSetMultimap.replaceValues.

Implements com.google.common.collect.SetMultimap.replaceValues, com.google.common.collect.Multimap.replaceValues.

Stores a collection of values with the same key, replacing any existing values for that key.
private static <K extends @Nullable Object, V extends @Nullable Object> void
pack-priv Iterator<V>
public Collection<V>
values()

Overrides com.google.common.collect.AbstractMapBasedMultimap.values.

Implements com.google.common.collect.Multimap.values.

Returns a collection of all values in the multimap.
pack-priv Spliterator<V>
private void