static class TreeBidiMap.Inverse extends java.lang.Object implements OrderedBidiMap
Modifier and Type | Field and Description |
---|---|
private java.util.Set |
entrySet
Store the entrySet once created.
|
private java.util.Set |
keySet
Store the keySet once created.
|
private TreeBidiMap |
main
The parent map.
|
private java.util.Set |
valuesSet
Store the valuesSet once created.
|
Constructor and Description |
---|
Inverse(TreeBidiMap main)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set |
entrySet() |
boolean |
equals(java.lang.Object obj) |
java.lang.Object |
firstKey()
Gets the first key currently in this map.
|
java.lang.Object |
get(java.lang.Object key) |
java.lang.Object |
getKey(java.lang.Object value)
Gets the key that is currently mapped to the specified value.
|
int |
hashCode() |
BidiMap |
inverseBidiMap()
Gets a view of this map where the keys and values are reversed.
|
OrderedBidiMap |
inverseOrderedBidiMap()
Gets a view of this map where the keys and values are reversed.
|
boolean |
isEmpty() |
java.util.Set |
keySet() |
java.lang.Object |
lastKey()
Gets the last key currently in this map.
|
MapIterator |
mapIterator()
Obtains a
MapIterator over the map. |
java.lang.Object |
nextKey(java.lang.Object key)
Gets the next key after the one specified.
|
OrderedMapIterator |
orderedMapIterator()
Obtains an
OrderedMapIterator over the map. |
java.lang.Object |
previousKey(java.lang.Object key)
Gets the previous key before the one specified.
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Puts the key-value pair into the map, replacing any previous pair.
|
void |
putAll(java.util.Map map) |
java.lang.Object |
remove(java.lang.Object key) |
java.lang.Object |
removeValue(java.lang.Object value)
Removes the key-value pair that is currently mapped to the specified
value (optional operation).
|
int |
size() |
java.lang.String |
toString() |
java.util.Collection |
values() |
private final TreeBidiMap main
private java.util.Set keySet
private java.util.Set valuesSet
private java.util.Set entrySet
Inverse(TreeBidiMap main)
main
- the main mappublic int size()
size
in interface java.util.Map
public boolean isEmpty()
isEmpty
in interface java.util.Map
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
public java.lang.Object getKey(java.lang.Object value)
BidiMap
If the value is not contained in the map, null
is returned.
Implementations should seek to make this method perform equally as well
as get(Object)
.
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
public java.lang.Object firstKey()
OrderedMap
firstKey
in interface OrderedMap
public java.lang.Object lastKey()
OrderedMap
lastKey
in interface OrderedMap
public java.lang.Object nextKey(java.lang.Object key)
OrderedMap
nextKey
in interface OrderedMap
key
- the key to search for next frompublic java.lang.Object previousKey(java.lang.Object key)
OrderedMap
previousKey
in interface OrderedMap
key
- the key to search for previous frompublic java.lang.Object put(java.lang.Object key, java.lang.Object value)
BidiMap
When adding a key-value pair, the value may already exist in the map against a different key. That mapping is removed, to ensure that the value only occurs once in the inverse map.
BidiMap map1 = new DualHashBidiMap(); map.put("A","B"); // contains A mapped to B, as per Map map.put("A","C"); // contains A mapped to C, as per Map BidiMap map2 = new DualHashBidiMap(); map.put("A","B"); // contains A mapped to B, as per Map map.put("C","B"); // contains C mapped to B, key A is removed
public void putAll(java.util.Map map)
putAll
in interface java.util.Map
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
public java.lang.Object removeValue(java.lang.Object value)
BidiMap
If the value is not contained in the map, null
is returned.
Implementations should seek to make this method perform equally as well
as remove(Object)
.
removeValue
in interface BidiMap
value
- the value to find the key-value pair fornull
if nothing removedpublic void clear()
clear
in interface java.util.Map
public java.util.Set keySet()
keySet
in interface java.util.Map
public java.util.Collection values()
values
in interface java.util.Map
public java.util.Set entrySet()
entrySet
in interface java.util.Map
public MapIterator mapIterator()
BidiMap
MapIterator
over the map.
A map iterator is an efficient way of iterating over maps. It does not require that the map is stored using Map Entry objects which can increase performance.
BidiMap map = new DualHashBidiMap(); MapIterator it = map.mapIterator(); while (it.hasNext()) { Object key = it.next(); Object value = it.getValue(); it.setValue("newValue"); }
mapIterator
in interface BidiMap
mapIterator
in interface IterableMap
public OrderedMapIterator orderedMapIterator()
OrderedMap
OrderedMapIterator
over the map.
A ordered map iterator is an efficient way of iterating over maps in both directions.
BidiMap map = new TreeBidiMap(); MapIterator it = map.mapIterator(); while (it.hasNext()) { Object key = it.next(); Object value = it.getValue(); it.setValue("newValue"); Object previousKey = it.previous(); }
orderedMapIterator
in interface OrderedMap
public BidiMap inverseBidiMap()
OrderedBidiMap
Changes to one map will be visible in the other and vice versa. This enables both directions of the map to be accessed equally.
Implementations should seek to avoid creating a new object every time this
method is called. See AbstractMap.values()
etc. Calling this
method on the inverse map should return the original.
Implementations must return an OrderedBidiMap
instance,
usually by forwarding to inverseOrderedBidiMap()
.
inverseBidiMap
in interface BidiMap
inverseBidiMap
in interface OrderedBidiMap
public OrderedBidiMap inverseOrderedBidiMap()
OrderedBidiMap
Changes to one map will be visible in the other and vice versa. This enables both directions of the map to be accessed equally.
Implementations should seek to avoid creating a new object every time this
method is called. See AbstractMap.values()
etc. Calling this
method on the inverse map should return the original.
inverseOrderedBidiMap
in interface OrderedBidiMap
public boolean equals(java.lang.Object obj)
equals
in interface java.util.Map
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Map
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object