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.
|
ListMultimap(Map<K,List<V>> orig)
Creates a copy of an existing map.
|
| 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.
|
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 ListMultimap(Map<K,List<V>> orig)
orig - the map 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 keyCopyright © 2013-2015 Michael Angstadt. All Rights Reserved.