public class MultiMap<K,V> extends java.lang.Object implements IMultiMap<K,V>
| Modifier and Type | Class and Description |
|---|---|
private static class |
MultiMap.EmptyMultiMap<K,V>
An immutable, empty multimap.
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<K,java.util.Set<V>> |
map
The backing map.
|
| Constructor and Description |
|---|
MultiMap()
Creates a new, empyt MultiMap.
|
MultiMap(int initialCapacity) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(K key,
V value)
Precondition: the mapping key→value is not already in the map.
|
void |
addAll(K key,
java.util.Collection<? extends V> values) |
void |
addAll(java.util.Map<? extends K,? extends V> m) |
void |
addAll(MultiMap<K,V> mmap) |
void |
clear() |
boolean |
contains(K obj) |
static <K,V> MultiMap<K,V> |
empty()
Returns an immutable, empty multimap.
|
java.util.Set<V> |
getValues(K key)
Returns the values that the given key maps to.
|
boolean |
isEmpty() |
java.util.Set<K> |
keySet()
Returns the set of keys in this map (the domain).
|
void |
put(K key,
java.util.Collection<? extends V> values)
Adds a key-values mapping to this multimap.
|
boolean |
remove(K key) |
boolean |
remove(K key,
V value)
Precondition: the mapping key→value is in the map.
|
int |
size()
Returns the size of this map: the number of mappings.
|
java.lang.String |
toString()
Returns a String representation of this map.
|
public MultiMap()
public MultiMap(int initialCapacity)
public static <K,V> MultiMap<K,V> empty()
K - the type of the keysV - the type of the valuespublic void put(K key, java.util.Collection<? extends V> values)
key - the keyvalues - the valuespublic boolean add(K key, V value)
IMultiMappublic boolean remove(K key, V value)
IMultiMappublic boolean remove(K key)
public java.util.Set<V> getValues(K key)
IMultiMappublic java.util.Set<K> keySet()
IMultiMappublic boolean contains(K obj)
public void clear()
public int size()
IMultiMappublic boolean isEmpty()