public class HashMultiMap<K,V> extends Object implements MultiMap<K,V>, Serializable
MultiMap
interface. This
implementation permits both null
keys and values.
This implementation provides constant time operations for the basic
operations put
and get
, assuming a uniform distribution of
hash keys.
HashMap
,
Serialized FormConstructor and Description |
---|
HashMultiMap() |
HashMultiMap(Map<? extends K,? extends V> m)
Constructs this map and adds in all the mapping from the provided
Map |
Modifier and Type | Method and Description |
---|---|
Map<K,Set<V>> |
asMap()
Returns a
Map -based view of this MultiMap |
void |
clear()
Removes all of the mappings from this multi-map.
|
boolean |
containsKey(Object key)
Returns
true if this multi-map contains a mapping for the
specified key. |
boolean |
containsMapping(Object key,
Object value)
Returns
true if this multi-map contains a mapping from specified
key to the specified value. |
boolean |
containsValue(Object value)
Returns
true if this multi-map contains from any key to the
specified value. |
Set<Map.Entry<K,V>> |
entrySet()
Returns a
Set view of all the key-value mappings contained in
this multi-map. |
Set<V> |
get(Object key)
Returns the set of values mapped to this key or
null of the key
is not mapped to any values |
boolean |
isEmpty()
Returns
true if this multi-map contains no mappings. |
Set<K> |
keySet()
Returns a
Set view of the mappings contained in this multi-map. |
boolean |
put(K key,
V value)
Adds the specified value to the set of values associated with the
specified key in this map.
|
void |
putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this mutli-map
|
void |
putAll(MultiMap<? extends K,? extends V> m)
Copies all of the mappings from the specified mulit-map to this mutli-map
|
boolean |
putMany(K key,
Collection<V> values)
Adds all of the specified values to the set of values associated with the
specified key in this map.
|
int |
range()
Returns the number of values maped to keys.
|
Set<V> |
remove(Object key)
Removes the mapping for a key from this multi-map if it is present,
returning any mapped values to that key
|
boolean |
remove(Object key,
Object value)
Removes the specified mapping for a key if it is present.
|
int |
size()
Returns the number of keys that are mapped to one or more values in this
multi-map.
|
String |
toString()
Returns the string form of this multi-map
|
Collection<V> |
values()
Returns a
Collection view of the values contained in this map. |
Collection<Set<V>> |
valueSets()
Returns a
Collection view of the sets of values mapped to each
key in this map. |
public void clear()
public boolean containsKey(Object key)
true
if this multi-map contains a mapping for the
specified key.containsKey
in interface MultiMap<K,V>
public boolean containsMapping(Object key, Object value)
true
if this multi-map contains a mapping from specified
key to the specified value.containsMapping
in interface MultiMap<K,V>
public boolean containsValue(Object value)
true
if this multi-map contains from any key to the
specified value.containsValue
in interface MultiMap<K,V>
public Set<Map.Entry<K,V>> entrySet()
Set
view of all the key-value mappings contained in
this multi-map.public Set<V> get(Object key)
null
of the key
is not mapped to any valuespublic boolean isEmpty()
true
if this multi-map contains no mappings.public boolean put(K key, V value)
public void putAll(Map<? extends K,? extends V> m)
public void putAll(MultiMap<? extends K,? extends V> m)
public boolean putMany(K key, Collection<V> values)
putMany
in interface MultiMap<K,V>
key
- key with which the specified value is to be associatedvalues
- a collection of values to be associated with the specified
keytrue
if at least one of the provided value was not
already in the set of value mapped to the specified keypublic int range()
MultiMap.size()
. However, in the case where a key is mapped to more
than one value, this method will always return a value strictly
larger than size()
.public Set<V> remove(Object key)
public boolean remove(Object key, Object value)
public int size()
size
in interface MultiMap<K,V>
MultiMap.range()
public String toString()
public Collection<V> values()
Collection
view of the values contained in this map. The collection and its Iterator
are backed by the
map, so changes to the map are reflected in the collection, and
vice-versa.public Collection<Set<V>> valueSets()
Collection
view of the sets of values mapped to each
key in this map.Copyright © 2012. All Rights Reserved.