org.knowceans.map
Class InvertibleTreeMultiMap<X,Y>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.TreeMap<X,java.util.Set<Y>>
          extended by org.knowceans.map.TreeMultiMap<X,Y>
              extended by org.knowceans.map.InvertibleTreeMultiMap<X,Y>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<X,java.util.Set<Y>>, java.util.NavigableMap<X,java.util.Set<Y>>, java.util.SortedMap<X,java.util.Set<Y>>, IMultiMap<X,Y>
Direct Known Subclasses:
RankingMap

public class InvertibleTreeMultiMap<X,Y>
extends TreeMultiMap<X,Y>

This object maps each key to a Set of values and holds each member of this Set as a link to a Set of keys, i.e., depicts a IMultiMap (object -> set) with an inverse IMultiMap. With getInverse(), the (forward) key set can easily be found from the (forward) value. This effectively implements an M to N relation.

In relational terms, this class implements an m:n relation.

Author:
heinrich
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
InvertibleTreeMultiMap()
           
InvertibleTreeMultiMap(java.util.Comparator<? super X> c)
           
InvertibleTreeMultiMap(java.util.Map m)
           
InvertibleTreeMultiMap(java.util.Map m, HashMultiMap<Y,X> inverse)
           
 
Method Summary
 void add(X key, Y value)
          adds the value to the key's value set and the key to the value's key set.
 void clear()
           
 IMultiMap<Y,X> getInverse()
          returns the hash map of the inverse (not that this is not a tree map).
 java.util.Set<X> getInverse(java.util.Set<Y> value)
          returns the keys that match a given set of value elements
 java.util.Set<X> getInverseValue(Y val)
          gets keys for a value as a Set.
static void main(java.lang.String[] args)
          some simple tests and demonstration for HashMultiMap
 java.util.Set<Y> put(X key, java.util.Set<Y> valSet)
          put a new key-valueSet pair.
 java.util.Set<Y> remove(java.lang.Object key)
          removes the (forward) key and its elements from it value set from the map that map to key.
 void remove(X key, Y value)
          removes the value from the key's mapping.
 
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clone, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, putAll, size, subMap, subMap, tailMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, size, values
 

Constructor Detail

InvertibleTreeMultiMap

public InvertibleTreeMultiMap()

InvertibleTreeMultiMap

public InvertibleTreeMultiMap(java.util.Comparator<? super X> c)
Parameters:
c -

InvertibleTreeMultiMap

public InvertibleTreeMultiMap(java.util.Map m)
Parameters:
m -

InvertibleTreeMultiMap

public InvertibleTreeMultiMap(java.util.Map m,
                              HashMultiMap<Y,X> inverse)
Parameters:
inverse - allow to set an inverse map that could be a tree map with its own comparator.
m -
Method Detail

main

public static void main(java.lang.String[] args)
some simple tests and demonstration for HashMultiMap

Parameters:
args -

clear

public void clear()
Specified by:
clear in interface java.util.Map<X,java.util.Set<Y>>
Overrides:
clear in class java.util.TreeMap<X,java.util.Set<Y>>

add

public void add(X key,
                Y value)
adds the value to the key's value set and the key to the value's key set.

Specified by:
add in interface IMultiMap<X,Y>
Overrides:
add in class TreeMultiMap<X,Y>
Parameters:
key - The key of the new entry.
value - The value of the new entry.

put

public java.util.Set<Y> put(X key,
                            java.util.Set<Y> valSet)
put a new key-valueSet pair. Value must be a Set. The old set of values must be removed if they don't , which places in the values set as well for every entry of the value, a In the inverse map, the (forward) key needs to be removed from the Set that is pointed to by its old value, and the key put to the Set for the new value.

Specified by:
put in interface java.util.Map<X,java.util.Set<Y>>
Overrides:
put in class TreeMultiMap<X,Y>

remove

public java.util.Set<Y> remove(java.lang.Object key)
removes the (forward) key and its elements from it value set from the map that map to key.

Specified by:
remove in interface java.util.Map<X,java.util.Set<Y>>
Overrides:
remove in class java.util.TreeMap<X,java.util.Set<Y>>

remove

public void remove(X key,
                   Y value)
removes the value from the key's mapping.

Specified by:
remove in interface IMultiMap<X,Y>
Overrides:
remove in class TreeMultiMap<X,Y>
Parameters:
key - The key of the new entry.
value - The value of the new entry.

getInverseValue

public java.util.Set<X> getInverseValue(Y val)
gets keys for a value as a Set.

Parameters:
val -
Returns:

getInverse

public java.util.Set<X> getInverse(java.util.Set<Y> value)
returns the keys that match a given set of value elements

Parameters:
value -
Returns:

getInverse

public IMultiMap<Y,X> getInverse()
returns the hash map of the inverse (not that this is not a tree map).

Returns: