|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sky.monome.util.ReversibleHashMap<K1,K2>
K1
- Type of keys in a normal way.K2
- Type of keys in a reversed way.public final class ReversibleHashMap<K1,K2>
Map in which both parameter types are keys inbetween.
In a normal way, K1
is the key and K2
is the value.
In a reversed way, K2
is the key and K1
is the value.
That implies that there will be no doublons in keys AND in values ! A protection mechanism look after that aspect permanently.
Note that it goes against standard Map
interface specifications.
This map works like a HashMap
since it internally contains HashMap
s.
This class is strongly thread-safe for all its methods. But you should iterate on it with external synchronization based on the internal lock object
accessible with the getLockObject()
method specified by the Synchronized
interface.
Why do you need a reversed map ? With classic maps, you can find a value associated with a specified key.
But you can't find a key associated with a specific value. With reversed maps, you can do that !
Synchronized
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
ReversibleHashMap()
Constructs an empty map. |
|
ReversibleHashMap(java.util.Map<? extends K1,? extends K2> map)
Constructs a map prefilled with all entries of specified map. |
Method Summary | |
---|---|
void |
clear()
Clears all key/value entries from this map. |
boolean |
containsKey(java.lang.Object key1)
Indicates whether this map contains the specified key in a normal way. |
boolean |
containsValue(java.lang.Object key2)
Indicates whether this map contains the specified value in a normal way. |
java.util.Set<java.util.Map.Entry<K1,K2>> |
entrySet()
Returns a set of all key/value entries contained by this map in a normal way. |
K2 |
get(java.lang.Object key1)
Returns the value associated with the specified key in a normal way. |
java.lang.Object |
getLockObject()
Returns the object over which the internal and external synchronization will operate. |
boolean |
isEmpty()
Indicates whether this map is empty. |
java.util.Set<K1> |
keySet()
Returns a set of all keys contained by this map in a normal way. |
K2 |
put(K1 key1,
K2 key2)
Adds or replaces the specified value associated with the specified key in a normal way. |
void |
putAll(java.util.Map<? extends K1,? extends K2> m)
Copies all key/value entries of the specified map into this map in a normal way. |
K2 |
remove(java.lang.Object key1)
Removes the value associated with the specified key in a normal way. |
boolean |
reversedContainsKey(java.lang.Object key2)
Indicates whether this map contains the specified key in a reversed way. |
boolean |
reversedContainsValue(java.lang.Object key1)
Indicates whether this map contains the specified value in a reversed way. |
java.util.Set<java.util.Map.Entry<K2,K1>> |
reversedEntrySet()
Returns a set of all key/value entries contained by this map in a reversed way. |
K1 |
reversedGet(java.lang.Object key2)
Returns the value associated with the specified key in a reversed way. |
java.util.Set<K2> |
reversedKeySet()
Returns a set of all keys contained by this map in a reversed way. |
K1 |
reversedPut(K2 key2,
K1 key1)
Adds or replaces the specified value associated with the specified key in a reversed way. |
void |
reversedPutAll(java.util.Map<? extends K2,? extends K1> m)
Copies all key/value entries of the specified map into this map in a reversed way. |
K1 |
reversedRemove(java.lang.Object key2)
Removes the value associated with the specified key in a reversed way. |
java.util.Collection<K1> |
reversedValues()
Returns a collection of all values contained by this map in a normal way. |
int |
size()
Returns the size of this map. |
java.util.Collection<K2> |
values()
Returns a collection of all values contained by this map in a normal way. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Constructor Detail |
---|
public ReversibleHashMap()
public ReversibleHashMap(java.util.Map<? extends K1,? extends K2> map)
map
- Map from which the new map will be prefilled.putAll(java.util.Map)
Method Detail |
---|
public int size()
size
in interface java.util.Map<K1,K2>
public boolean isEmpty()
isEmpty
in interface java.util.Map<K1,K2>
true
if this map is empty, false
otherwise.public boolean containsKey(java.lang.Object key1)
containsKey
in interface java.util.Map<K1,K2>
key1
- Key to look for.
true
if this map contains the specified key, false
otherwise.public boolean reversedContainsKey(java.lang.Object key2)
key2
- Key to look for.
true
if this map contains the specified key, false
otherwise.public boolean containsValue(java.lang.Object key2)
containsValue
in interface java.util.Map<K1,K2>
key2
- Value to look for.
true
if this map contains the specified value, false
otherwise.public boolean reversedContainsValue(java.lang.Object key1)
key1
- Value to look for.
true
if this map contains the specified value, false
otherwise.public K2 get(java.lang.Object key1)
get
in interface java.util.Map<K1,K2>
key1
- Key to find.
public K1 reversedGet(java.lang.Object key2)
key2
- Key to find.
public K2 put(K1 key1, K2 key2)
put
in interface java.util.Map<K1,K2>
key1
- Key to find or to add.key2
- Value to associate to the key.
null
if the key was not found previously in this map.
Returning null
can also indicate that the value null
was previously associated to the key.public K1 reversedPut(K2 key2, K1 key1)
key2
- Key to find or to add.key1
- Value to associate to the key.
null
if the key was not found previously in this map.
Returning null
can also indicate that the value null
was previously associated to the key.public K2 remove(java.lang.Object key1)
remove
in interface java.util.Map<K1,K2>
key1
- Key to find and to remove.
null
if the key was not found previously in this map.
Returning null
can also indicate that the value null
was previously associated to the key.public K1 reversedRemove(java.lang.Object key2)
key2
- Key to find and to remove.
null
if the key was not found previously in this map.
Returning null
can also indicate that the value null
was previously associated to the key.public void putAll(java.util.Map<? extends K1,? extends K2> m)
putAll
in interface java.util.Map<K1,K2>
m
- Map from which key/value entries will be copied.public void reversedPutAll(java.util.Map<? extends K2,? extends K1> m)
m
- Map from which key/value entries will be copied.public void clear()
clear
in interface java.util.Map<K1,K2>
public java.util.Set<K1> keySet()
keySet
in interface java.util.Map<K1,K2>
public java.util.Set<K2> reversedKeySet()
public java.util.Collection<K2> values()
values
in interface java.util.Map<K1,K2>
public java.util.Collection<K1> reversedValues()
public java.util.Set<java.util.Map.Entry<K1,K2>> entrySet()
entrySet
in interface java.util.Map<K1,K2>
public java.util.Set<java.util.Map.Entry<K2,K1>> reversedEntrySet()
public java.lang.Object getLockObject()
getLockObject
in interface Synchronized
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |