harpoon.Util.Collections
Class GenericInvertibleMultiMap

java.lang.Object
  |
  +--harpoon.Util.Collections.GenericInvertibleMultiMap
All Implemented Interfaces:
BinaryRelation, InvertibleMultiMap, Map, MultiMap

public class GenericInvertibleMultiMap
extends Object
implements InvertibleMultiMap

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.

Version:
$Id: GenericInvertibleMultiMap.java,v 1.2 2002/02/25 21:09:04 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>

Nested Class Summary
 
Nested classes inherited from class harpoon.Util.Collections.MultiMap
MultiMap.Factory
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Constructor Summary
GenericInvertibleMultiMap()
           
GenericInvertibleMultiMap(CollectionFactory cf)
           
GenericInvertibleMultiMap(Map m)
           
GenericInvertibleMultiMap(MapFactory mf, CollectionFactory cf)
           
GenericInvertibleMultiMap(MultiMap.Factory mmf)
           
GenericInvertibleMultiMap(MultiMap mm)
           
 
Method Summary
 boolean add(Object key, Object value)
          Ensures that this contains an association from key to value.
 boolean addAll(MultiMap mm)
          Adds all mappings in the given multimap to this multimap.
 boolean addAll(Object key, Collection values)
          Adds to the current mappings: associations for key to each value in values.
 void clear()
           
 boolean contains(Object a, Object b)
          Returns true if a has a mapping to b in this.
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set entrySet()
          The Set returned by this method is actually an instance of MultiMapSet.
 boolean equals(Object o)
           
 Object get(Object key)
          Returns some arbitrary value from the collection of values to which this map maps the specified key.
 Collection getValues(Object key)
          Returns the collection of Values associated with key.
 int hashCode()
           
 InvertibleMultiMap invert()
          Returns an unmodifiable inverted view of this.
 boolean isEmpty()
           
 Set keySet()
           
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this map, after removing all old values associated with the key.
 void putAll(Map t)
          Copies the mappings from the specified map to this map, after removing all old values associated with the key.
 Object remove(Object key)
          Removes mappings from key to all associated values from this map.
 boolean remove(Object key, Object value)
          Removes a mapping from key to value from this map if present.
 boolean removeAll(Object key, Collection values)
          Removes from the current mappings: associations for key to any value in values.
 boolean retainAll(Object key, 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).
 String toString()
           
 Collection values()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GenericInvertibleMultiMap

public GenericInvertibleMultiMap(MultiMap.Factory mmf)

GenericInvertibleMultiMap

public GenericInvertibleMultiMap(MapFactory mf,
                                 CollectionFactory cf)

GenericInvertibleMultiMap

public GenericInvertibleMultiMap(CollectionFactory cf)

GenericInvertibleMultiMap

public GenericInvertibleMultiMap()

GenericInvertibleMultiMap

public GenericInvertibleMultiMap(Map m)

GenericInvertibleMultiMap

public GenericInvertibleMultiMap(MultiMap mm)
Method Detail

invert

public InvertibleMultiMap invert()
Returns an unmodifiable inverted view of this.

Specified by:
invert in interface InvertibleMultiMap

add

public boolean add(Object key,
                   Object value)
Description copied from interface: MultiMap
Ensures that this contains an association from key to value. (MultiMap specific operation).

Specified by:
add in interface MultiMap
Returns:
true if this mapping changed as a result of the call

addAll

public boolean addAll(Object key,
                      Collection values)
Description copied from interface: MultiMap
Adds to the current mappings: associations for key to each value in values. (MultiMap specific operation).

Specified by:
addAll in interface MultiMap
Returns:
true if this mapping changed as a result of the call

addAll

public boolean addAll(MultiMap mm)
Description copied from interface: MultiMap
Adds all mappings in the given multimap to this multimap.

Specified by:
addAll in interface MultiMap

clear

public void clear()
Specified by:
clear in interface Map

contains

public boolean contains(Object a,
                        Object b)
Description copied from interface: MultiMap
Returns true if a has a mapping to b in this. (MultiMap specific operation).

Specified by:
contains in interface MultiMap

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map

entrySet

public Set entrySet()
The Set returned by this method is actually an instance of MultiMapSet.

Specified by:
entrySet in interface Map

equals

public boolean equals(Object o)
Specified by:
equals in interface Map
Overrides:
equals in class Object

get

public Object get(Object key)
Description copied from interface: MultiMap
Returns some arbitrary value from the collection of values to which this map maps the specified key. Returns 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.

Specified by:
get in interface MultiMap

getValues

public Collection getValues(Object key)
Description copied from interface: MultiMap
Returns the collection of Values associated with key. 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).

Specified by:
getValues in interface MultiMap

hashCode

public int hashCode()
Specified by:
hashCode in interface Map
Overrides:
hashCode in class Object

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map

keySet

public Set keySet()
Specified by:
keySet in interface Map

put

public Object put(Object key,
                  Object value)
Description copied from interface: MultiMap
Associates the specified value with the specified key in this map, after removing all old values associated with the key. Returns some value that was previously associated with the specified key, or null if no values were associated previously.

Specified by:
put in interface MultiMap

putAll

public void putAll(Map t)
Description copied from interface: MultiMap
Copies the mappings from the specified map to this map, after removing all old values associated with the key. Note that putAll(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 addAll(MultiMap).

Specified by:
putAll in interface MultiMap

remove

public Object remove(Object key)
Description copied from interface: MultiMap
Removes mappings from key to all associated values from this map. This is consistent with the Map definition of remove.

Specified by:
remove in interface MultiMap
Returns:
one of the previous values associated with the key, or 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).

remove

public boolean remove(Object key,
                      Object value)
Description copied from interface: MultiMap
Removes a mapping from key to value from this map if present. (MultiMap 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.

Specified by:
remove in interface MultiMap

removeAll

public boolean removeAll(Object key,
                         Collection values)
Description copied from interface: MultiMap
Removes from the current mappings: associations for key to any value in values. (MultiMap specific operation).

Specified by:
removeAll in interface MultiMap
Returns:
true if this mapping changed as a result of the call

retainAll

public boolean retainAll(Object key,
                         Collection values)
Description copied from interface: MultiMap
Removes from the current mappings: associations for key to any value not in values. (MultiMap specific operation).

Specified by:
retainAll in interface MultiMap
Returns:
true if this mapping changed as a result of the call

size

public int size()
Description copied from interface: MultiMap
Returns the number of key-value mappings in this map (keys which map to multiple values count multiple times).

Specified by:
size in interface MultiMap

toString

public String toString()
Overrides:
toString in class Object

values

public Collection values()
Specified by:
values in interface Map