|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.common.collect.LinkedListMultimap<K,V>
public final class LinkedListMultimap<K,V>
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,
Multimap<K,V> map = ... map.put(key1, foo); map.put(key2, bar); map.put(key1, baz);In this case, the iteration order for
keys() would be [key1,
key2, key1], and likewise for entries(). Unlike LinkedHashMultimap, the iteration order is kept consistent between keys,
entries and values. For example, calling
map.remove(key1, foo);changes the entries iteration order to
[key2=baz, key1=baz] and the
key iteration order to [key2, key1]. The entries() iterator
returns mutable map entries, and replaceValues(K, java.lang.Iterable extends V>) attempts to preserve
iteration order as much as possible.
All optional multimap methods are supported, and all returned views are modifiable.
The methods get(K), 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 own remove
operation, the results of the iteration are undefined.
| Constructor Summary | |
|---|---|
LinkedListMultimap()
Constructs an empty LinkedListMultimap. |
|
LinkedListMultimap(Multimap<? extends K,? extends V> multimap)
Constructs a LinkedListMultimap with the same mappings as the
specified Multimap. |
|
| Method Summary | |
|---|---|
Map<K,Collection<V>> |
asMap()
Returns a map view that associates each key with the corresponding values in the multimap. |
void |
clear()
Removes all key-value pairs from the multimap. |
boolean |
containsEntry(Object key,
Object value)
Returns true if the multimap contains the specified key-value pair. |
boolean |
containsKey(Object key)
Returns true if the multimap contains any values for the specified
key. |
boolean |
containsValue(Object value)
Returns true if the multimap contains the specified value for any
key. |
Collection<Map.Entry<K,V>> |
entries()
Returns a collection of all key-value pairs. |
boolean |
equals(Object other)
Compares the specified object to this multimap for equality. |
List<V> |
get(K key)
Returns a collection view of all values associated with a key. If no mappings in the multimap have the provided key, an empty collection is returned. Changes to the returned collection will update the underlying multimap, and vice versa. |
int |
hashCode()
Returns the hash code for this multimap. |
boolean |
isEmpty()
Returns true if the multimap contains no key-value pairs. |
Multiset<K> |
keys()
Returns a collection, which may contain duplicates, of all keys. |
Set<K> |
keySet()
Returns the set of all keys, each appearing once in the returned set. |
boolean |
put(K key,
V value)
Stores a key-value pair in the multimap. |
void |
putAll(K key,
Iterable<? extends V> values)
Stores a collection of values with the same key. |
void |
putAll(Multimap<? extends K,? extends V> multimap)
Copies all of another multimap's key-value pairs into this multimap. |
boolean |
remove(Object key,
Object value)
Removes a key-value pair from the multimap. |
List<V> |
removeAll(Object key)
Removes all values associated with a given key. |
List<V> |
replaceValues(K key,
Iterable<? extends V> values)
Stores a collection of values with the same key, replacing any existing values for that key. |
int |
size()
Returns the number of key-value pairs in the multimap. |
String |
toString()
Returns a string representation of the multimap, generated by calling toString on the map returned by Multimap.asMap(). |
Collection<V> |
values()
Returns a collection of all values in the multimap. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public LinkedListMultimap()
LinkedListMultimap.
public LinkedListMultimap(Multimap<? extends K,? extends V> multimap)
LinkedListMultimap with the same mappings as the
specified Multimap.
| Method Detail |
|---|
public int size()
Multimap
size in interface Multimap<K,V>public boolean isEmpty()
Multimaptrue if the multimap contains no key-value pairs.
isEmpty in interface Multimap<K,V>
public boolean containsKey(@Nullable
Object key)
Multimaptrue if the multimap contains any values for the specified
key.
containsKey in interface Multimap<K,V>key - key to search for in multimap
public boolean containsValue(@Nullable
Object value)
Multimaptrue if the multimap contains the specified value for any
key.
containsValue in interface Multimap<K,V>value - value to search for in multimap
public boolean containsEntry(@Nullable
Object key,
@Nullable
Object value)
Multimaptrue if the multimap contains the specified key-value pair.
containsEntry in interface Multimap<K,V>key - key to search for in multimapvalue - value to search for in multimap
public boolean put(@Nullable
K key,
@Nullable
V value)
put in interface Multimap<K,V>key - key to store in the multimapvalue - value to store in the multimap
true always
public boolean remove(@Nullable
Object key,
@Nullable
Object value)
Multimap
remove in interface Multimap<K,V>key - key of entry to remove from the multimapvalue - value of entry to remove the multimap
true if the multimap changed
public void putAll(@Nullable
K key,
Iterable<? extends V> values)
Multimap
putAll in interface Multimap<K,V>key - key to store in the multimapvalues - values to store in the multimappublic void putAll(Multimap<? extends K,? extends V> multimap)
Multimapmultimap.entries().
putAll in interface Multimap<K,V>multimap - mappings to store in this multimap
public List<V> replaceValues(@Nullable
K key,
Iterable<? extends V> values)
Because the values for a given key may have duplicates and follow the
insertion ordering, this method returns a List, instead of the
Collection specified in the Multimap interface.
If any entries for the specified key already exist in the
multimap, their values are changed in-place without affecting the iteration
order.
replaceValues in interface ListMultimap<K,V>replaceValues in interface Multimap<K,V>key - key to store in the multimapvalues - values to store in the multimap
public List<V> removeAll(@Nullable
Object key)
ListMultimapBecause the values for a given key may have duplicates and follow the
insertion ordering, this method returns a List, instead of the
Collection specified in the Multimap interface.
removeAll in interface ListMultimap<K,V>removeAll in interface Multimap<K,V>key - key of entries to remove from the multimap
public void clear()
Multimap
clear in interface Multimap<K,V>
public List<V> get(@Nullable
K key)
Changes to the returned collection will update the underlying multimap, and vice versa.
Because the values for a given key may have duplicates and follow the
insertion ordering, this method returns a List, instead of the
Collection specified in the Multimap interface.
If the multimap is modified while an iteration over the list is in
progress (except through the iterator's own add, set or
remove operations) the results of the iteration are undefined.
get in interface ListMultimap<K,V>get in interface Multimap<K,V>key - key to search for in multimap
public Set<K> keySet()
Multimap
keySet in interface Multimap<K,V>public Multiset<K> keys()
Multimap
keys in interface Multimap<K,V>public Collection<V> values()
The iterator generated by the returned collection traverses the values in the order they were added to the multimap.
values in interface Multimap<K,V>public Collection<Map.Entry<K,V>> entries()
add or addAll operations.
The iterator generated by the returned collection traverses the entries in the order they were added to the multimap.
entries in interface Multimap<K,V>public Map<K,Collection<V>> asMap()
ListMultimapsetValue() on the map entries, put, or putAll.
The collections returned by asMap().get(Object) have the same
behavior as those returned by Multimap.get(K).
Though the method signature doesn't say so explicitly, the returned map
has List values.
asMap in interface ListMultimap<K,V>asMap in interface Multimap<K,V>public boolean equals(Object other)
Two ListMultimap instances are equal if, for each key, they
contain the same values in the same order. If the value orderings disagree,
the multimaps will not be considered equal.
equals in interface ListMultimap<K,V>equals in interface Multimap<K,V>equals in class Objectpublic int hashCode()
The hash code of a multimap is defined as the hash code of the map view,
as returned by Multimap.asMap().
hashCode in interface Multimap<K,V>hashCode in class Objectpublic String toString()
toString on the map returned by Multimap.asMap().
toString in class Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||