|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractMap<K,V> java.util.HashMap<X,Y> org.knowceans.map.InvertibleHashMap<X,Y>
public class InvertibleHashMap<X,Y>
HashMap that keeps an inverse. With getInverse(), the (forward) key can easily be found from the (forward) value.
In relational terms, this class implements an n:1 relation.
By convention, this class does not permit null values.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Constructor Summary | |
---|---|
InvertibleHashMap()
|
|
InvertibleHashMap(IMultiMap<Y,X> inverse)
allows to set an inverse type, for instance to sort by value using a TreeMultiMap |
Method Summary | |
---|---|
void |
checkConsistency()
performs a simple check of consistency of the inverse with the forward map by a check if every value-key pair corresponds to a key-value pair with identical references and vice versa. |
void |
clear()
|
IMultiMap<Y,X> |
getInverse()
never use for write operations. |
java.util.Set<X> |
getInverse(java.lang.Object val)
gets keys for a value as a Set. |
java.util.Set<Y> |
getInverseKeys()
returns the keys of the inverse map. |
static void |
main(java.lang.String[] args)
|
Y |
put(X key,
Y val)
put a new key-value pair. |
Y |
remove(java.lang.Object key)
removes the (forward) key and its value from the map. |
Methods inherited from class java.util.HashMap |
---|
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, 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 |
---|
equals, hashCode |
Constructor Detail |
---|
public InvertibleHashMap()
public InvertibleHashMap(IMultiMap<Y,X> inverse)
Method Detail |
---|
public static void main(java.lang.String[] args)
public void clear()
clear
in interface java.util.Map<X,Y>
clear
in class java.util.HashMap<X,Y>
public Y put(X key, Y val)
put
in interface java.util.Map<X,Y>
put
in class java.util.HashMap<X,Y>
public Y remove(java.lang.Object key)
remove
in interface java.util.Map<X,Y>
remove
in class java.util.HashMap<X,Y>
public java.util.Set<X> getInverse(java.lang.Object val)
val
-
public java.util.Set<Y> getInverseKeys()
public IMultiMap<Y,X> getInverse()
TODO: return UnmodifiableMap but that's not subclass of IMultiMap.
public void checkConsistency()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |