K
- the keyV
- the valuepublic class ListMultimap<K,V>
extends java.lang.Object
implements java.lang.Iterable<java.util.Map.Entry<K,java.util.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(java.lang.Object obj) |
V |
first(K key)
Gets the first value that's associated with a key.
|
java.util.List<V> |
get(K key)
Gets the values associated with the key.
|
java.util.Map<K,java.util.List<V>> |
getMap()
Gets the underlying
Map object. |
int |
hashCode() |
boolean |
isEmpty()
Determines if the multimap is empty or not.
|
java.util.Iterator<java.util.Map.Entry<K,java.util.List<V>>> |
iterator() |
java.util.Set<K> |
keySet()
Returns all the keys.
|
void |
put(K key,
V value)
Adds a value to the multimap.
|
void |
putAll(K key,
java.util.Collection<V> values)
Adds multiple values to the multimap.
|
boolean |
remove(K key,
V value)
Removes a particular value.
|
java.util.List<V> |
removeAll(K key)
Removes all the values associated with a key
|
java.util.List<V> |
replace(K key,
java.util.Collection<V> values)
Replaces all values with the given values.
|
java.util.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.
|
java.lang.String |
toString() |
java.util.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 void put(K key, V value)
key
- the keyvalue
- the value to addpublic void putAll(K key, java.util.Collection<V> values)
key
- the keyvalues
- the values to addpublic java.util.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 java.util.List<V> removeAll(K key)
key
- the key to removepublic java.util.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 java.util.List<V> replace(K key, java.util.Collection<V> values)
key
- the keyvalues
- the values with which to replace all existing valuespublic void clear()
public java.util.Set<K> keySet()
public java.util.List<V> values()
public boolean isEmpty()
public int size()
public java.util.Map<K,java.util.List<V>> getMap()
Map
object.Map
objectprotected K sanitizeKey(K key)
key
- the keypublic java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
This software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.