K
- the keyV
- the valuepublic class ListMultimap<K,V> extends Object implements Iterable<Map.Entry<K,List<V>>>
ArrayList
objects to store its values. The
internal Map
implementation is a LinkedHashMap
.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>> map)
Creates a new multimap backed by the given map.
|
Modifier and Type | Method and Description |
---|---|
Map<K,List<V>> |
asMap()
Gets an immutable view of the underlying
Map object. |
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
Map that backs this multimap. |
int |
hashCode() |
boolean |
isEmpty()
Determines if the multimap is empty or not.
|
Iterator<Map.Entry<K,List<V>>> |
iterator()
Gets an iterator for iterating over the entries in the map.
|
Set<K> |
keySet()
Gets all the keys in the multimap.
|
void |
put(K key,
V value)
Adds a value to the multimap.
|
void |
putAll(K key,
Collection<? extends 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<? extends 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()
Gets the number of values in the map.
|
String |
toString() |
List<V> |
values()
Gets all the values in the multimap.
|
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 ListMultimap(Map<K,List<V>> map)
Creates a new multimap backed by the given map. Changes made to the given map will effect the multimap and vice versa.
To avoid problems, it is highly recommended that the given map NOT be
modified by anything other than this ListMultimap
class after
being passed into this constructor.
map
- the backing mappublic void put(K key, V value)
key
- the keyvalue
- the value to addpublic void putAll(K key, Collection<? extends 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<? extends V> values)
key
- the keyvalues
- the values with which to replace all existing valuespublic void clear()
public Set<K> keySet()
public List<V> values()
public boolean isEmpty()
public int size()
public Map<K,List<V>> asMap()
Map
object.public Map<K,List<V>> getMap()
Map
that backs this multimap. This method is here for
performances reasons. The returned map should NOT be modified by anything
other than the ListMultimap
object that owns it.protected K sanitizeKey(K key)
key
- the keypublic Iterator<Map.Entry<K,List<V>>> iterator()
Copyright © 2013–2024 Michael Angstadt. All rights reserved.