K
- the keyV
- the valuepublic class ListMultimap<K,V> extends Object implements Iterable<Map.Entry<K,List<V>>>
List
objects to store its values. The internal
Map
implementation is a LinkedHashMap
that uses
ArrayList
for its values.Constructor and Description |
---|
ListMultimap()
Creates an empty multimap.
|
ListMultimap(int initialCapacity)
Creates an empty multimap.
|
ListMultimap(ListMultimap<K,V> orig)
Creates a copy of an existing multimap.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all entries from the multimap.
|
boolean |
containsKey(K key)
Determines whether the given key exists.
|
boolean |
equals(Object obj) |
V |
first(K key)
Gets the first value that's associated with a key.
|
List<V> |
get(K key)
Gets the values associated with the key.
|
Map<K,List<V>> |
getMap()
Gets the underlying
Map object. |
int |
hashCode() |
boolean |
isEmpty()
Determines if the multimap is empty or not.
|
Iterator<Map.Entry<K,List<V>>> |
iterator() |
Set<K> |
keySet()
Returns all the keys.
|
void |
put(K key,
V value)
Adds a value to the multimap.
|
void |
putAll(K key,
Collection<V> values)
Adds multiple values to the multimap.
|
boolean |
remove(K key,
V value)
Removes a particular value.
|
List<V> |
removeAll(K key)
Removes all the values associated with a key
|
List<V> |
replace(K key,
Collection<V> values)
Replaces all values with the given values.
|
List<V> |
replace(K key,
V value)
Replaces all values with the given value.
|
protected K |
sanitizeKey(K key)
Modifies a given key before it is used to interact with the internal map.
|
int |
size()
Returns the number of values in the map.
|
String |
toString() |
List<V> |
values()
Returns all the values.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public ListMultimap()
public ListMultimap(int initialCapacity)
initialCapacity
- the initial capacity of the underlying map.public ListMultimap(ListMultimap<K,V> orig)
orig
- the multimap to copy frompublic void put(K key, V value)
key
- the keyvalue
- the value to addpublic void putAll(K key, Collection<V> values)
key
- the keyvalues
- the values to addpublic List<V> get(K key)
key
- the keypublic V first(K key)
key
- the keypublic boolean containsKey(K key)
key
- the keypublic boolean remove(K key, V value)
key
- the keyvalue
- the value to removepublic List<V> removeAll(K key)
key
- the key to removepublic List<V> replace(K key, V value)
key
- the keyvalue
- the value with which to replace all existing values, or null
to remove all valuespublic List<V> replace(K key, Collection<V> values)
key
- the keyvalues
- the values with which to replace all existing valuespublic void clear()
public boolean isEmpty()
public int size()
public Map<K,List<V>> getMap()
Map
object.Map
objectprotected K sanitizeKey(K key)
key
- the keyThis software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.