public class GenericInvertibleMultiMap<K,V> extends java.lang.Object implements InvertibleMultiMap<K,V>
GenericInvertibleMultiMap is a default implementation of
InvertibleMultiMap. It returns modifiable inverted
views of the mappings it maintains. Note that a
GenericInvertibleMultiMap can directly replace a
GenericInvertibleMap, because MultiMap
correctly extends Map.| Constructor and Description |
|---|
GenericInvertibleMultiMap() |
GenericInvertibleMultiMap(CollectionFactory cf) |
GenericInvertibleMultiMap(java.util.Map<? extends K,? extends V> m) |
GenericInvertibleMultiMap(MapFactory mf,
CollectionFactory cf) |
GenericInvertibleMultiMap(MultiMap<? extends K,? extends V> mm) |
GenericInvertibleMultiMap(MultiMapFactory mmf) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(K key,
V value)
Ensures that
this contains an association from
key to value. |
boolean |
addAll(K key,
java.util.Collection<? extends V> values)
Adds to the current mappings: associations for
key to each value in values. |
boolean |
addAll(MultiMap<? extends K,? extends V> mm)
Adds all mappings in the given multimap to this multimap.
|
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()
The
Set returned by this method is actually an
instance of MultiMapSet. |
boolean |
equals(java.lang.Object o) |
V |
get(java.lang.Object key)
Returns some arbitrary value from the collection 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. |
int |
hashCode() |
InvertibleMultiMap<V,K> |
invert()
Returns an unmodifiable inverted view of
this. |
boolean |
isEmpty() |
java.util.Set<K> |
keySet() |
V |
put(K key,
V value)
Associates the specified value with the specified key in this
map, after removing all old values associated with the key.
|
void |
putAll(java.util.Map<? extends K,? extends V> t)
Copies the mappings from the specified map to this
map, after removing all old values associated with the key.
|
V |
remove(java.lang.Object key)
Removes mappings from key to all associated values from this map.
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
Removes a mapping from key to value from this map if present.
|
boolean |
removeAll(K key,
java.util.Collection<?> values)
Removes from the current mappings: associations for
key to any value in values. |
boolean |
retainAll(K key,
java.util.Collection<?> values)
Removes from the current mappings: associations for
key to any value not in values. |
int |
size()
Returns the number of key-value mappings in this map (keys which
map to multiple values count multiple times).
|
java.lang.String |
toString() |
java.util.Collection<V> |
values() |
public GenericInvertibleMultiMap(MultiMapFactory mmf)
public GenericInvertibleMultiMap(MapFactory mf, CollectionFactory cf)
public GenericInvertibleMultiMap(CollectionFactory cf)
public GenericInvertibleMultiMap()
public GenericInvertibleMultiMap(java.util.Map<? extends K,? extends V> m)
public InvertibleMultiMap<V,K> invert()
this.invert in interface InvertibleMap<K,V>invert in interface InvertibleMultiMap<K,V>public boolean addAll(K key, java.util.Collection<? extends V> values)
MultiMapkey to each value in values.
(MultiMap specific operation).public boolean addAll(MultiMap<? extends K,? extends V> mm)
MultiMappublic boolean contains(java.lang.Object a,
java.lang.Object b)
MultiMappublic boolean containsKey(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
public MultiMapSet<K,V> entrySet()
Set returned by this method is actually an
instance of MultiMapSet.public boolean equals(java.lang.Object o)
public V get(java.lang.Object key)
MultiMapnull 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 java.util.Collection<V> getValues(K key)
MultiMapkey. Modifications to the returned
Collection affect this as well. If
there are no Values currently associated with
key, constructs a new, potentially mutable, empty
Collection and returns it.
(MultiMap specific operation).public int hashCode()
public V put(K key, V value)
MultiMapnull if no values were
associated previously.public void putAll(java.util.Map<? extends K,? extends V> t)
MultiMapputAll(mm) where mm is a
MultiMap will NOT add all of the mappings in
mm; it will only add all of the Keys in
mm, mapping each Key to one of the Values it
mapped to in mm. To add all of the mappings from
another MultiMap, use
MultiMap.addAll(MultiMap).public V remove(java.lang.Object key)
MultiMapMap definition of
remove.remove in interface java.util.Map<K,V>remove in interface MultiMap<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)
MultiMapMultiMap specific operation).
Note that if multiple mappings from key to value are permitted
by this map, then only one is guaranteed to be removed.
Returns true if this was modified as a result of
this operation, else returns false.public boolean removeAll(K key, java.util.Collection<?> values)
MultiMapkey to any value in values.
(MultiMap specific operation).public boolean retainAll(K key, java.util.Collection<?> values)
MultiMapkey to any value not in values.
(MultiMap specific operation).public int size()
MultiMappublic java.lang.String toString()
toString in class java.lang.ObjectCopyright (c) 2006 C. Scott Ananian