|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface MultiMap<K,V>
A map which allows multiple values per key. This interface is similar to
Map, but while the entries in an ordinary map have unique
keys, the entries in a multi-map are unqiue by key/value pair.
The behavior of a multi-map is undefined if its keys are mutable.
As with the standard Java collections classes, instances of MultiMap are unsynchronized. See net.innig.collect.InnigCollections for synchronizedMultiMap() and unmodifiableMultiMap() methods.
The Jakarta Commons Collections package also provides a MultiMap. I like mine a bit better -- instead of extending Map (which ends up breaking the Map contract), it provides a set of methods more particularly tailored to the behavior of a MultiMap. However, the Jakarta Collections are more widely accepted, and are a generally excellent package, so I certainly recommend checking them out!
| Maturity: This is a 90% mature API. |
| Plans: There are no current plans to expand or revise this interface. |
InnigCollections| Nested Class Summary | |
|---|---|
static interface |
MultiMap.Entry<EK,EV>
Represents a single key/value pair in the multi-map. |
| Method Summary | |
|---|---|
void |
clear()
Clears all entries. |
boolean |
containsKey(K key)
Returns true if there is at least one mapping for the given key. |
boolean |
containsValue(V value)
Returns true if there is at least one key which maps to the given values. |
java.util.Set<MultiMap.Entry<K,V>> |
entrySet()
Returns the set of key/value pairs in this multi-map. |
boolean |
equals(java.lang.Object o)
Two multi-maps are equal iff they contain the same key/value mappings. |
java.util.Set<V> |
get(K key)
Returns the set of values for a given key. |
int |
hashCode()
|
boolean |
isEmpty()
Returns true if there are no mappings. |
java.util.Set<K> |
keySet()
Returns the set of keys in this multi-map. |
boolean |
put(K key,
V value)
Adds a mapping from a key to a value. |
boolean |
putAll(K key,
java.util.Collection<? extends V> values)
Adds mappings from a key to several different values. |
void |
putAll(java.util.Map<? extends K,? extends V> map)
Adds all entries from a map to this multi-map. |
void |
putAll(MultiMap<? extends K,? extends V> multimap)
Adds all entries from another multi-map to this one. |
boolean |
remove(K key,
V value)
Removes a key/value mapping. |
java.util.Set<V> |
removeKey(K key)
Removes all key/value mappings for a given key. |
int |
size()
Returns the number of key/value mappings in the multi-map. |
java.util.Collection<V> |
values()
Returns the values in this multi-map. |
| Method Detail |
|---|
int size()
boolean isEmpty()
boolean containsKey(K key)
boolean containsValue(V value)
java.util.Set<V> get(K key)
boolean put(K key,
V value)
boolean putAll(K key,
java.util.Collection<? extends V> values)
boolean remove(K key,
V value)
java.util.Set<V> removeKey(K key)
void putAll(MultiMap<? extends K,? extends V> multimap)
void putAll(java.util.Map<? extends K,? extends V> map)
void clear()
java.util.Set<K> keySet()
java.util.Collection<V> values()
java.util.Set<MultiMap.Entry<K,V>> entrySet()
boolean equals(java.lang.Object o)
equals in class java.lang.Objectint hashCode()
hashCode in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||