org.knowceans.map
Class HashMultiMap<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>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<X,java.util.Set<Y>>, IMultiMap<X,Y>, IPatternMap<X,java.util.Set<Y>>
Direct Known Subclasses:
InvertibleHashMultiMap

public class HashMultiMap<X,Y>
extends java.util.HashMap<X,java.util.Set<Y>>
implements IMultiMap<X,Y>, IPatternMap<X,java.util.Set<Y>>

Implementation of the IMultiMap interface backed by a HashMap. Maps a key to a Set of values.

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

This multimap supports wildcard and pattern search, however based on full iteration of the mapEntries. (TODO: put in better algorithm for wildcard expansion).

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
HashMultiMap()
           
 
Method Summary
 void add(X key, Y value)
          add a value to the set of values for a key.
 java.util.Hashtable<X,java.util.Set<Y>> getPattern(java.lang.String pattern)
          get all entries that match a specific pattern.
 java.util.Hashtable<X,java.util.Set<Y>> getWildcard(java.lang.String wildcard)
          return all entries that match a specific wildcard.
 boolean isPatternCaseInsensitive()
           
 boolean isPatternMustMatch()
           
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.
 void setPatternCaseInsensitive(boolean b)
           
 void setPatternMustMatch(boolean b)
           
 
Methods inherited from class java.util.HashMap
clear, 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
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, values
 

Constructor Detail

HashMultiMap

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

getPattern

public java.util.Hashtable<X,java.util.Set<Y>> getPattern(java.lang.String pattern)
get all entries that match a specific pattern. This implementation uses complete iteration over all entries and returns a Hashtable

Specified by:
getPattern in interface IPatternMap<X,java.util.Set<Y>>
Parameters:
pattern -
Returns:

getWildcard

public java.util.Hashtable<X,java.util.Set<Y>> getWildcard(java.lang.String wildcard)
return all entries that match a specific wildcard.

Specified by:
getWildcard in interface IPatternMap<X,java.util.Set<Y>>
Returns:

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.

isPatternCaseInsensitive

public boolean isPatternCaseInsensitive()
Returns:

isPatternMustMatch

public boolean isPatternMustMatch()
Returns:

setPatternCaseInsensitive

public void setPatternCaseInsensitive(boolean b)
Parameters:
b -

setPatternMustMatch

public void setPatternMustMatch(boolean b)
Parameters:
b -