|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.common.collect.ArrayListMultimap<K,V>
public final class ArrayListMultimap<K,V>
Implementation of Multimap that uses an ArrayList to store
the values for a given key. A HashMap associates each key with an
ArrayList of values.
When iterating through the collections supplied by this class, the ordering of values for a given key agrees with the order in which the values were added.
This multimap allows duplicate key-value pairs. After adding a new
key-value pair equal to an existing key-value pair, the ArrayListMultimap will contain entries for both the new value and the old
value.
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(com.google.common.collect.ListMultimap.
| Constructor Summary | |
|---|---|
ArrayListMultimap()
Constructs an empty ArrayListMultimap. |
|
ArrayListMultimap(int distinctKeys,
int valuesPerKey)
Constructs an empty ArrayListMultimap with the expected number of
distinct keys and the expected number of values per distinct key. |
|
ArrayListMultimap(Multimap<? extends K,? extends V> multimap)
Constructs an ArrayListMultimap with the same mappings as the
specified Multimap. |
|
| Method Summary | |
|---|---|
java.util.Map<K,java.util.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(java.lang.Object key,
java.lang.Object value)
Returns true if the multimap contains the specified key-value pair. |
boolean |
containsKey(java.lang.Object key)
Returns true if the multimap contains any values for the specified
key. |
boolean |
containsValue(java.lang.Object value)
Returns true if the multimap contains the specified value for any
key. |
java.util.Collection<java.util.Map.Entry<K,V>> |
entries()
Returns a collection of all key-value pairs. |
boolean |
equals(java.lang.Object obj)
Compares the specified object to this multimap for equality. |
java.util.List<V> |
get(K key)
Returns a collection view of all values associated with a key. |
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. |
java.util.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,
java.lang.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(java.lang.Object key,
java.lang.Object value)
Removes a key-value pair from the multimap. |
java.util.List<V> |
removeAll(java.lang.Object key)
Removes all values associated with a given key. |
java.util.List<V> |
replaceValues(K key,
java.lang.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. |
java.lang.String |
toString()
Returns a string representation of the multimap, generated by calling toString on the map returned by Multimap.asMap(). |
void |
trimToSize()
Reduces the memory used by this ArrayListMultimap, if feasible. |
java.util.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 |
| Methods inherited from interface com.google.common.collect.ListMultimap |
|---|
asMap |
| Methods inherited from interface com.google.common.collect.Multimap |
|---|
clear, containsEntry, containsKey, containsValue, entries, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, size, values |
| Constructor Detail |
|---|
public ArrayListMultimap()
ArrayListMultimap.
public ArrayListMultimap(int distinctKeys,
int valuesPerKey)
ArrayListMultimap with the expected number of
distinct keys and the expected number of values per distinct key.
distinctKeys - the expected number of distinct keysvaluesPerKey - the expected number of values per distinct key
java.lang.IllegalArgumentException - if either argument is negativepublic ArrayListMultimap(Multimap<? extends K,? extends V> multimap)
ArrayListMultimap with the same mappings as the
specified Multimap.
| Method Detail |
|---|
public void trimToSize()
ArrayListMultimap, if feasible.
public java.util.List<V> get(@Nullable
K key)
Changes to the returned collection will update the underlying multimap, and vice versa.
The returned collection is not serializable.
get in interface ListMultimap<K,V>get in interface Multimap<K,V>key - key to search for in multimap
public java.util.List<V> removeAll(@Nullable
java.lang.Object key)
Multimap
removeAll in interface ListMultimap<K,V>removeAll in interface Multimap<K,V>key - key of entries to remove from the multimap
public java.util.List<V> replaceValues(@Nullable
K key,
java.lang.Iterable<? extends V> values)
Multimap
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 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 equals(@Nullable
java.lang.Object obj)
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>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
java.lang.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
java.lang.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
java.lang.Object key,
@Nullable
java.lang.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 remove(@Nullable
java.lang.Object key,
@Nullable
java.lang.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,
java.lang.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 multimappublic void clear()
Multimap
clear in interface Multimap<K,V>public java.util.Set<K> keySet()
Multimap
keySet in interface Multimap<K,V>public Multiset<K> keys()
Multimap
keys in interface Multimap<K,V>public java.util.Collection<V> values()
The iterator generated by the returned collection traverses the values for one key, followed by the values of a second key, and so on.
values in interface Multimap<K,V>public java.util.Collection<java.util.Map.Entry<K,V>> entries()
add or addAll operations.
The iterator generated by the returned collection traverses the values for one key, followed by the values of a second key, and so on.
entries in interface Multimap<K,V>public java.util.Map<K,java.util.Collection<V>> asMap()
MultimapsetValue() on its entries, put, or putAll.
The collections returned by asMap().get(Object) have the same
behavior as those returned by Multimap.get(K).
asMap in interface Multimap<K,V>public 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 java.lang.ObjectMap.hashCode()public java.lang.String toString()
toString on the map returned by Multimap.asMap().
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||