K
- the class of keysV
- the class of valuespublic class MultiMap<K,V> extends Object implements Iterable<V>
HashMap
for the map part and a HashSet
for the multiple values part.
Using this map any key can map to any number of values. null values and keys
are permitted by implementation.
This class is actually a decorator of a HashMap
instance, for the
Map
interface forces the entrySet() method to return a set of entries
(Key, Set(Value)), while a set of entries (Key, Value) was preferred in this
implementation. Same issue for the iterator.
Modifier and Type | Field and Description |
---|---|
private HashMap<K,HashSet<V>> |
_map
The decorated
HashMap . |
Constructor and Description |
---|
MultiMap()
Basic constructor, instantiates the decorated map with an empty
instance of
HashMap . |
MultiMap(Map<? extends K,? extends V> m)
Copy constructor, instantiates the decorated map and then copy the
parameter entries into the new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the map, removing from index all keys and their associated
values.
|
boolean |
containsKey(K key)
Returns whether the map contains the key given in parameter.
|
boolean |
containsValue(V value)
Returns whether the map contains the given value is present in the map.
|
Set<Map.Entry<K,V>> |
entrySet()
|
boolean |
equals(Object o)
|
Set<V> |
get(K key)
Getter on the set of values associated with a given key.
|
boolean |
isEmpty()
Returns whether the map contains no key at all.
|
Iterator<V> |
iterator()
|
Set<K> |
keySet()
|
V |
put(K key,
V value)
Add a given value to a given key in the
MultiMap . |
void |
putAll(Map<? extends K,? extends Set<V>> m)
|
Set<V> |
remove(K key)
Remove a key and its values from the MultiMap.
|
V |
remove(K key,
V value)
Remove a given value from the set associated to a given key.
|
int |
size()
Computes the size of the decorated map.
|
int |
totalSize()
Computes the total size of the decorated map.
|
Collection<V> |
values()
generate a
HashSet containing all values stored in the
MultiMap. |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public MultiMap()
HashMap
.public int size()
public int totalSize()
public boolean isEmpty()
true
if the map contains no key, false
otherwise.public boolean containsKey(K key)
key
- The key to be tested. true
if the key is present in the map, false
else.public boolean containsValue(V value)
value
- The value to be tested.true
if the value is present in the map, false
otherwise.public void clear()
public Set<V> get(K key)
key
- The given key.public Set<V> remove(K key)
key
- The key to remove.null
otherwise.public V remove(K key, V value)
key
- The key from which remove the value.value
- The value to remove.null
otherwise.public void putAll(Map<? extends K,? extends Set<V>> m)
m
- The map from which extract keys and values.public Collection<V> values()
HashSet
containing all values stored in the
MultiMap.MultiMap
.public V put(K key, V value)
MultiMap
.key
- The given key.value
- The given value to add.public boolean equals(Object o)
Copyright © 2017–2019 UniversitĂ© CĂ´te d'Azur, CNRS, I3S. All rights reserved.