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

public Class LinkedListMultimap<K extends @Nullable Object, V extends @Nullable Object>

extends AbstractMultimap<K extends @Nullable Object, V extends @Nullable Object>
implements ListMultimap<K extends @Nullable Object, V extends @Nullable Object>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.google.common.collect.ListMultimap, com.google.common.collect.Multimap
Annotations
@GwtCompatible
serializable:true
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, .Preconditions.checkPositionIndex, .Preconditions.checkState, java.util.Collections.unmodifiableList, .Objects.requireNonNull

An implementation of ListMultimap that supports deterministic iteration order for both keys and values. The iteration order is preserved across non-distinct key values. For example, for the following multimap definition:
Multimap<K, V> multimap = LinkedListMultimap.create();
multimap.put(key1, foo);
multimap.put(key2, bar);
multimap.put(key1, baz);
... the iteration order for keys() is [key1, key2, key1], and similarly for entries(). Unlike LinkedHashMultimap, the iteration order is kept consistent between keys, entries and values. For example, calling:
multimap.remove(key1, foo);

changes the entries iteration order to [key2=bar, key1=baz] and the key iteration order to [key2, key1]. The entries() iterator returns mutable map entries, and replaceValues attempts to preserve iteration order as much as possible.

The collections returned by keySet() 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(), keys(), and values iterate across the key-value mappings in the order they were added to the multimap.

The values() and entries() methods both return a List, instead of the Collection specified by the ListMultimap interface.

The methods get, keySet(), keys(), values, entries(), and asMap return collections that are views of the multimap. If the multimap is modified while an iteration over any of those collections is in progress, except through the iterator's methods, the results of the iteration are undefined.

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#synchronizedListMultimap.

See the Guava User Guide article on Multimap.

Author
Mike Bostock
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
LinkedListMultimap.DistinctKeyIterator

An Iterator over distinct keys in key head order.

private static class
private static class
private class
LinkedListMultimap.NodeIterator

An Iterator over all nodes.

private class
LinkedListMultimap.ValueForKeyIterator

A ListIterator over values for a specified key.

Field Summary

Modifier and TypeField and Description
private transient LinkedListMultimap.Node<K, V>
private transient Map<K, LinkedListMultimap.KeyList<K, V>>
private transient int
private static final long
private transient int
private transient LinkedListMultimap.Node<K, V>

Constructor Summary

AccessConstructor and Description
pack-priv
private
LinkedListMultimap(int expectedKeys)

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

Method Summary

Modifier and TypeMethod and Description
private LinkedListMultimap.Node<K, V>
addNode(K key, V value, LinkedListMultimap.Node<K, V> nextSibling)

Adds a new node for the specified key-value pair before the specified nextSibling element, or at the end of the list if nextSibling is null.

public void
clear()

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

Removes all key-value pairs from the multimap, leaving it empty.
public boolean
containsKey(Object key)

Implements com.google.common.collect.Multimap.containsKey.

Returns true if this multimap contains at least one key-value pair with the key key.
public boolean
containsValue(Object value)

Overrides com.google.common.collect.AbstractMultimap.containsValue.

Implements com.google.common.collect.Multimap.containsValue.

Returns true if this multimap contains at least one key-value pair with the value value.
public static <K extends @Nullable Object, V extends @Nullable Object> LinkedListMultimap<K, V>
create()

Creates a new, empty LinkedListMultimap with the default initial capacity.

public static <K extends @Nullable Object, V extends @Nullable Object> LinkedListMultimap<K, V>
create(int
the expected number of distinct keys
expectedKeys
)

Constructs an empty LinkedListMultimap with enough capacity to hold the specified number of keys without rehashing.

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

Constructs a LinkedListMultimap with the same mappings as the specified Multimap.

pack-priv Map<K, Collection<V>>
pack-priv List<Map.Entry<K, V>>
pack-priv Multiset<K>
pack-priv Set<K>
pack-priv List<V>
public List<Map.Entry<K, V>>
entries()

Overrides com.google.common.collect.AbstractMultimap.entries.

Implements com.google.common.collect.Multimap.entries.

Returns a view collection of all key-value pairs contained in this multimap, as Entry instances.
pack-priv Iterator<Map.Entry<K, V>>
public List<V>
get(final K key)

Implements com.google.common.collect.ListMultimap.get, com.google.common.collect.Multimap.get.

Returns a view collection of the values associated with key in this multimap, if any.
private List<V>
getCopy(K key)

public boolean
isEmpty()

Overrides com.google.common.collect.AbstractMultimap.isEmpty.

Implements com.google.common.collect.Multimap.isEmpty.

Returns true if this multimap contains no key-value pairs.
public boolean

Returns:

true always
put
(K
key to store in the multimap
key
,
V
value to store in the multimap
value
)

Overrides com.google.common.collect.AbstractMultimap.put.

Implements com.google.common.collect.Multimap.put.

Stores a key-value pair in the multimap.
private void
public List<V>
private void
removeAllNodes(K key)

Removes all nodes for the specified key.

private void
removeNode(LinkedListMultimap.Node<K, V> node)

Removes the specified node from the linked list.

public List<V>
replaceValues(K key, Iterable<? extends V> values)

Overrides com.google.common.collect.AbstractMultimap.replaceValues.

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

Stores a collection of values with the same key, replacing any existing values for that key.
public int
size()

Implements com.google.common.collect.Multimap.size.

Returns the number of key-value pairs in this multimap.
public List<V>
values()

Overrides com.google.common.collect.AbstractMultimap.values.

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

Returns a view collection containing the value from each key-value pair contained in this multimap, without collapsing duplicates (so values().size() == size()).
private void
Inherited from com.google.common.collect.AbstractMultimap:
asMapcontainsEntryentrySpliteratorequalshashCodekeyskeySetputAllputAllremovetoStringvalueIteratorvalueSpliterator