K
- the type of the keys the map uses.V
- the type of the values the map uses.public class MultiMap<K,V> extends Object
This MultiMap uses a LinkedHashMap
together with a ArrayList
in order to keep the order of its entries.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAP_SIZE
The constant value 6.
|
Constructor and Description |
---|
MultiMap()
Constructs a new MultiMap with a initial capacity of
DEFAULT_MAP_SIZE . |
MultiMap(int size)
Constructs a new MultiMap.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
List<V> |
getAll(Object key)
Get all values for the given key.
|
V |
getFirst(Object key)
Get the first value for the given key, or
null if there are no entries. |
boolean |
isEmpty() |
Set<K> |
keySet() |
boolean |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> map) |
V |
remove(Object key)
Removes all mappings for the given key and returns the first value if there where mappings or
null if not. |
boolean |
removeOne(Object key,
V value)
Remove the mapping of the given key to the value.
|
int |
size() |
List<V> |
values()
Returns a new list containing all values of this multi map.
|
public static final int DEFAULT_MAP_SIZE
public MultiMap()
DEFAULT_MAP_SIZE
.public MultiMap(int size)
size
- the initial capacity.public int size()
public boolean isEmpty()
public boolean containsKey(Object key)
public boolean containsValue(Object value)
public V getFirst(Object key)
null
if there are no entries.key
- public List<V> getAll(Object key)
Changes to the returned set will update the underlying MultiMap if the return set is not empty.
key
- public V remove(Object key)
null
if not.key
- public boolean removeOne(Object key, V value)
Returns true
if the mapping was removed and false
if the mapping did not exist.
key
- value
- public void clear()
public List<V> values()