public class GenericMultiMap<K,V> extends AbstractMultiMap<K,V>
GenericMultiMap is a default implementation of a
MultiMap.
FSK: right now the implementation tries to preserve the property that if a key 'k' maps to an empty collection 'c' in some MultiMap 'mm', then users of 'mm' will not be able to see that 'k' is a member of the keySet for 'mm'. However, it does not preserve this property when mm.getValues(k) is used as a means to operate on the state of 'mm', and it is not clear to me whether one can even ensure that the property can be maintained if arbitrary operations on mm.getValues(k) are passed on to 'mm'.
| Constructor and Description |
|---|
GenericMultiMap()
|
GenericMultiMap(CollectionFactory<V> cf)
Creates a
MultiMap using a HashMap for
the map and the specified CollectionFactory to
create the value collections. |
GenericMultiMap(MapFactory<K,java.util.Collection<V>> mf,
CollectionFactory<V> cf)
Creates a
MultiMap using the specified
MapFactory to create the map and the specified
CollectionFactory to create the value collections. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
contains(java.lang.Object a,
java.lang.Object b)
Returns true if
a has a mapping to b
in this. |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
MultiMapSet<K,V> |
entrySet()
Returns a set view of the mappings contained in this map.
|
V |
get(java.lang.Object key)
Returns some arbitrary value from the set of values to which
this map maps the specified key.
|
java.util.Collection<V> |
getValues(K key)
Returns the collection of Values associated with
key. |
boolean |
isEmpty() |
java.util.Set<K> |
keySet()
Returns a set view of the keys in this map.
|
V |
remove(java.lang.Object key)
Removes all mappings for this key from this map if present.
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
Removes a mapping from key to value from this map if present.
|
int |
size()
Returns the number of key-value mappings in this map (keys which
map to multiple values count multiple times).
|
java.util.Collection<V> |
values()
Returns a collection view of the values contained in this
map.
|
add, addAll, addAll, equals, hashCode, put, putAll, removeAll, retainAll, toStringpublic GenericMultiMap()
MultiMap using a HashMap for
the map and HashSets for the value collections.
To gain more control over the specific sets/map used in
internal representation of this, use the more
specific constructor
that takes CollectionFactorys.public GenericMultiMap(CollectionFactory<V> cf)
MultiMap using a HashMap for
the map and the specified CollectionFactory to
create the value collections.public GenericMultiMap(MapFactory<K,java.util.Collection<V>> mf, CollectionFactory<V> cf)
MultiMap using the specified
MapFactory to create the map and the specified
CollectionFactory to create the value collections.public int size()
MultiMappublic boolean isEmpty()
public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<K,V>containsKey in class AbstractMultiMap<K,V>public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<K,V>containsValue in class AbstractMultiMap<K,V>public V get(java.lang.Object key)
null if
the map contains no mapping for the key; it's also possible
that the map explicitly maps the key to null.
The containsKey operation may be used to
distinquish these two cases.
Note that if only the put method is used to
modify this, then get will operate
just as it would in any other Map.public V remove(java.lang.Object key)
null if there was no mapping for key.remove in interface java.util.Map<K,V>remove in interface MultiMap<K,V>remove in class AbstractMultiMap<K,V>null if Map associated
no values with the key. Note that a zero-sized collection
is not returned in the latter case, and that a
null return value may be ambiguous if the map
associated null with the given key (in addition
to possibly other values).public boolean remove(java.lang.Object key,
java.lang.Object value)
this was modified as a result of
this operation, else returns false.public void clear()
public java.util.Collection<V> getValues(K key)
key. Modifications to the returned
Collection affect this as well. If
there are no Values currently associated with
key, constructs a new, mutable, empty
Collection and returns it.
(MultiMap specific operation).public boolean contains(java.lang.Object a,
java.lang.Object b)
public java.util.Set<K> keySet()
public java.util.Collection<V> values()
public MultiMapSet<K,V> entrySet()
Map.Entrys. The returned set is actually a
MultiMapSet, from which you can get back the
original MultiMap.Copyright (c) 2006 C. Scott Ananian