|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface MultiMap<K,V>
Defines a map that holds a collection of values against each key.
AMultiMap
is a Map with slightly different semantics.
Putting a value into the map will add the value to a Collection at that key.
Getting a value will return a Collection, holding all the values put to that key.
For example:
Number key = new Integer(5); MultiMap<Number,String> mhm = new MultiHashMap<Number,String>(); mhm.put(key, "A"); mhm.put(key, "B"); mhm.put(key, "C"); Collection<String> coll = mhm.get(key);
coll
will be a collection containing "A", "B", "C".
NOTE: Note: this new, generics-friendly version of the MultiMap interface does
NOT extend java.util.Map! This is because MultiMap breaks the Map contract in
too many ways to allow generics support. However, you can get a live java.util.Map
for a MultiMap with the method map()
.
Method Summary | |
---|---|
void |
clear()
Removes all mappings from this map (optional operation). |
boolean |
containsKey(Object key)
Returns true if this map contains a mapping for the specified key. |
boolean |
containsValue(Object value)
Checks whether the map contains the value specified. |
boolean |
containsValue(Object key,
Object value)
Checks whether the map contains the value specified, at the key specified. |
Set<Map.Entry<K,Collection<V>>> |
entrySet()
Returns a set view of the mappings contained in this map. |
boolean |
equals(Object o)
Compares the specified object with this map for equality. |
Collection<V> |
get(Object key)
Gets the collection of values associated with the specified key. |
int |
hashCode()
Returns the hash code value for this map. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
Iterator<V> |
iterator(Object key)
|
Set<K> |
keySet()
Returns a set view of the keys contained in this map. |
Map<K,Collection<V>> |
map()
Returns a java.util.Map<K,Collection<V>> for this MultiMap. |
V |
put(K key,
V value)
Adds the value to the collection associated with the specified key. |
boolean |
putAll(K key,
Collection<? extends V> values)
Copies all of the values in the given collection in to the multimap against the given key. |
void |
putAll(Map<? extends K,? extends V> t)
Copies all of the mappings from the specified map to this map (optional operation). |
void |
putAll(MultiMap<? extends K,? extends V> t)
Copies all of the mappings from the specified multimap to this multimap (optional operation). |
Collection<V> |
remove(Object key)
Removes all values associated with the specified key. |
V |
remove(Object key,
Object item)
Removes a specific value from map. |
int |
size()
Gets the number of keys in this map. |
int |
size(Object key)
Gets the number of values in this map for the given key. |
Collection<V> |
values()
Gets a collection containing all the values in the map. |
Method Detail |
---|
V remove(Object key, Object item)
null
from a subsequant get(Object)
, however
they may choose to return an empty collection.
key
- the key to remove fromitem
- the item to remove
UnsupportedOperationException
- if the map is unmodifiable
ClassCastException
- if the key or value is of an invalid type
NullPointerException
- if the key or value is null and null is invalidint size(Object key)
int size()
Collection<V> get(Object key)
Collection
. Implementations
are free to declare that they return Collection
subclasses
such as List
or Set
.
Implementations return null
if no values have
been mapped to the key.
Implementations may choose to return a clone of the internal collection.
key
- the key to retrieve
Collection
of values, implementations should
return null
for no mapping, but may return an empty collection
ClassCastException
- if the key is of an invalid type
NullPointerException
- if the key is null and null keys are invalidboolean containsValue(Object value)
value
- the value to search for
ClassCastException
- if the value is of an invalid type
NullPointerException
- if the value is null and null value are invalidboolean containsValue(Object key, Object value)
value
- the value to search forkey
- the key against which to search for the value
ClassCastException
- if the value is of an invalid type
NullPointerException
- if the value is null and null value are invalidV put(K key, V value)
Map
the previous value is not replaced.
Instead the new value is added to the collection stored against the key.
The collection may be a List
, Set
or other
collection dependent on implementation.
key
- the key to store againstvalue
- the value to add to the collection at the key
UnsupportedOperationException
- if the map is unmodifiable
ClassCastException
- if the key or value is of an invalid type
NullPointerException
- if the key or value is null and null is invalid
IllegalArgumentException
- if the key or value is invalidCollection<V> remove(Object key)
null
from a subsequent
get(Object)
, however they may choose to return an empty collection.
key
- the key to remove values from
Collection
of values removed, implementations should
return null
for no mapping found, but may return an empty collection
UnsupportedOperationException
- if the map is unmodifiable
ClassCastException
- if the key is of an invalid type
NullPointerException
- if the key is null and null keys are invalidCollection<V> values()
boolean isEmpty()
boolean containsKey(Object key)
key
- key whose presence in this map is to be tested.
ClassCastException
- if the key is of an inappropriate type for
this map (optional).
NullPointerException
- if the key is null and this map
does not permit null keys (optional).void putAll(Map<? extends K,? extends V> t)
put(k, v)
on this map once
for each mapping from key k to value v in the
specified map. The behavior of this operation is unspecified if the
specified map is modified while the operation is in progress.
t
- Mappings to be stored in this map.
UnsupportedOperationException
- if the putAll method is
not supported by this map.
ClassCastException
- if the class of a key or value in the
specified map prevents it from being stored in this map.
IllegalArgumentException
- some aspect of a key or value in the
specified map prevents it from being stored in this map.
NullPointerException
- if the specified map is null, or if
this map does not permit null keys or values, and the
specified map contains null keys or values.void putAll(MultiMap<? extends K,? extends V> t)
put(k, v)
on this map once
for each mapping from key to collections15 of values in the
specified multimap. The behavior of this operation is unspecified if the
specified multimap is modified while the operation is in progress.
t
- Mappings to be stored in this map.
UnsupportedOperationException
- if the putAll method is
not supported by this map.
ClassCastException
- if the class of a key or value in the
specified map prevents it from being stored in this map.
IllegalArgumentException
- some aspect of a key or value in the
specified map prevents it from being stored in this map.
NullPointerException
- if the specified map is null, or if
this map does not permit null keys or values, and the
specified map contains null keys or values.boolean putAll(K key, Collection<? extends V> values)
key
- the key against which to store the values.values
- the collection of values to map to the key.Iterator<V> iterator(Object key)
void clear()
UnsupportedOperationException
- clear is not supported by this
map.Set<K> keySet()
Set<Map.Entry<K,Collection<V>>> entrySet()
Map.Entry
. The set is backed by the
map, so changes to the map are reflected in the set, and vice-versa.
If the map is modified while an iteration over the set is in progress
(except through the iterator's own remove operation, or through
the setValue operation on a map entry returned by the iterator)
the results of the iteration are undefined. The set supports element
removal, which removes the corresponding mapping from the map, via the
Iterator.remove, Set.remove, removeAll,
retainAll and clear operations. It does not support
the add or addAll operations.
Map<K,Collection<V>> map()
boolean equals(Object o)
equals
in class Object
o
- object to be compared for equality with this map.
int hashCode()
hashCode
in class Object
Map.Entry#hashCode()
,
Object.hashCode()
,
Object.equals(Object)
,
equals(Object)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |