org.apache.commons.collections
Interface MultiMap
- Map
- MultiHashMap
public interface MultiMap
extends Map
Defines a map that holds a collection of values against each key.
A
MultiMap
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:
MultiMap mhm = new MultiHashMap();
mhm.put(key, "A");
mhm.put(key, "B");
mhm.put(key, "C");
Collection coll = (Collection) mhm.get(key);
coll
will be a collection containing "A", "B", "C".
NOTE: Additional methods were added to this interface in Commons Collections 3.1.
These were added solely for documentation purposes and do not change the interface
as they were defined in the superinterface
Map
anyway.
$Revision: 1.12 $ $Date: 2004/03/14 15:33:57 $- Christopher Berry
- James Strachan
- Stephen Colebourne
boolean | containsValue(Object value) - Checks whether the map contains the value specified.
|
Object | get(Object key) - Gets the collection of values associated with the specified key.
|
Object | put(Object key, Object value) - Adds the value to the collection associated with the specified key.
|
Object | remove(Object key) - Removes all values associated with the specified key.
|
Object | remove(Object key, Object item) - Removes a specific value from map.
|
int | size() - Gets the number of keys in this map.
|
Collection | values() - Gets a collection containing all the values in the map.
|
containsValue
public boolean containsValue(Object value)
Checks whether the map contains the value specified.
Implementations typically check all collections against all keys for the value.
This cannot be mandated due to backwards compatability of this interface.
value
- the value to search for
- true if the map contains the value
get
public Object get(Object key)
Gets the collection of values associated with the specified key.
The returned value will implement
Collection
. Implementations
are free to declare that they return
Collection
subclasses
such as
List
or
Set
.
Implementations typically return
null
if no values have
been mapped to the key, however the implementation may choose to
return an empty collection.
Implementations may choose to return a clone of the internal collection.
key
- the key to retrieve
- the
Collection
of values, implementations should
return null
for no mapping, but may return an empty collection
put
public Object put(Object key,
Object value)
Adds the value to the collection associated with the specified key.
Unlike a normal
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
- typically the value added if the map changed and null if the map did not change
remove
public Object remove(Object key)
Removes all values associated with the specified key.
Implementations typically return
null
from a subsequant
get(Object)
, however they may choose to return an empty collection.
key
- the key to remove values from
- the
Collection
of values removed, implementations should
return null
for no mapping found, but may return an empty collection
remove
public Object remove(Object key,
Object item)
Removes a specific value from map.
The item is removed from the collection mapped to the specified key.
Other values attached to that key are unaffected.
If the last value for a key is removed, implementations typically
return
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
- the value removed (which was passed in), null if nothing removed
size
public int size()
Gets the number of keys in this map.
Implementations typically return only the count of keys in the map
This cannot be mandated due to backwards compatability of this interface.
- the number of key-collection mappings in this map
values
public Collection values()
Gets a collection containing all the values in the map.
Inplementations typically return a collection containing the combination
of values from all keys.
This cannot be mandated due to backwards compatability of this interface.
- a collection view of the values contained in this map
Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.