org.knowceans.map
Class TreeMultiMap<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>
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:
InvertibleTreeMultiMap, PatternTreeMultiMap

public class TreeMultiMap<X,Y>
extends java.util.TreeMap<X,java.util.Set<Y>>
implements IMultiMap<X,Y>

Implementation of the IMultiMap interface backed by a TreeMap. Maps a key to a Set of values and orders by the key's Comparator.

In relational terms, this class implements a m:n relation, but without reverse lookup.

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
TreeMultiMap()
           
TreeMultiMap(java.util.Comparator<? super X> c)
           
TreeMultiMap(java.util.Map<X,java.util.Set<Y>> m)
           
TreeMultiMap(java.util.Map<X,java.util.Set<Y>> m, java.util.Comparator<? super X> c)
           
 
Method Summary
 void add(X key, Y value)
          add a value to the set of values for a key.
static void main(java.lang.String[] args)
           
 java.util.Set<Y> put(X key, java.util.Set<Y> value)
          put a complete Set of values to a key.
 void remove(X key, Y value)
          remove one value out of the set of values for one key.
 
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, 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, remove, 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
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, values
 

Constructor Detail

TreeMultiMap

public TreeMultiMap()

TreeMultiMap

public TreeMultiMap(java.util.Comparator<? super X> c)

TreeMultiMap

public TreeMultiMap(java.util.Map<X,java.util.Set<Y>> m)

TreeMultiMap

public TreeMultiMap(java.util.Map<X,java.util.Set<Y>> m,
                    java.util.Comparator<? super X> c)
Method Detail

main

public static void main(java.lang.String[] args)

add

public void add(X key,
                Y value)
add a value to the set of values for a key.

Specified by:
add in interface IMultiMap<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> value)
put a complete Set of values to a key.
To prevent ClassCastException in add(X, Y), we must ensure that only Sets ever get put into this map. Using JSR14, this would not be a problem.

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

remove

public void remove(X key,
                   Y value)
remove one value out of the set of values for one key. (the remove (key) method removes the complete key and set of values.

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