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

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<X,java.util.Set<Y>>
          extended by org.knowceans.map.HashMultiMap<X,Y>
              extended by org.knowceans.map.InvertibleHashMultiMap<X,Y>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<X,java.util.Set<Y>>, IInvertibleMap<X,java.util.Set<Y>>, IInvertibleMultiMap<X,Y>, IMultiMap<X,Y>, IPatternMap<X,java.util.Set<Y>>

public class InvertibleHashMultiMap<X,Y>
extends HashMultiMap<X,Y>
implements IInvertibleMultiMap<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
InvertibleHashMultiMap()
           
 
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()
           
 java.util.Set<X> getInverse(java.util.Set<Y> value)
          returns the keys that match a given set of value elements
 java.util.Set<Y> getInverseKeys()
          returns the keys of the inverse map.
 java.util.Set<X> getInverseValue(Y val)
          gets keys for a value as a Set.
 java.util.Hashtable<Y,java.util.Set<X>> getPatternInverse(java.lang.String a)
          Returns inverse pattern mapping, specifically for string values in the map.
 java.util.Hashtable<Y,java.util.Set<X>> getWildcardInverse(java.lang.String a)
          Returns inverse wildcard mapping, specifically for string values in the map.
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(X 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 org.knowceans.map.HashMultiMap
getPattern, getWildcard, isPatternCaseInsensitive, isPatternMustMatch, setPatternCaseInsensitive, setPatternMustMatch
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, 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, remove, size, values
 

Constructor Detail

InvertibleHashMultiMap

public InvertibleHashMultiMap()
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.HashMap<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 HashMultiMap<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 HashMultiMap<X,Y>

remove

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


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 HashMultiMap<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.

Specified by:
getInverseValue in interface IInvertibleMultiMap<X,Y>
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

Specified by:
getInverse in interface IInvertibleMap<X,java.util.Set<Y>>
Parameters:
value -
Returns:

getInverse

public IMultiMap<Y,X> getInverse()

getPatternInverse

public java.util.Hashtable<Y,java.util.Set<X>> getPatternInverse(java.lang.String a)
Returns inverse pattern mapping, specifically for string values in the map.

Parameters:
a -
Returns:
See Also:
HashMultiMap#getPattern();

getWildcardInverse

public java.util.Hashtable<Y,java.util.Set<X>> getWildcardInverse(java.lang.String a)
Returns inverse wildcard mapping, specifically for string values in the map.

Parameters:
a -
Returns:
See Also:
HashMultiMap#getPattern();

getInverseKeys

public java.util.Set<Y> getInverseKeys()
returns the keys of the inverse map. Use this preferably over values().

Returns: