Class TreeBidiMap.Inverse
- All Implemented Interfaces:
Map
,BidiMap
,IterableMap
,OrderedBidiMap
,OrderedMap
- Enclosing class:
TreeBidiMap
-
Nested Class Summary
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
boolean
firstKey()
Gets the first key currently in this map.Gets the key that is currently mapped to the specified value.int
hashCode()
Gets a view of this map where the keys and values are reversed.Gets a view of this map where the keys and values are reversed.boolean
isEmpty()
keySet()
lastKey()
Gets the last key currently in this map.Obtains aMapIterator
over the map.Gets the next key after the one specified.Obtains anOrderedMapIterator
over the map.previousKey
(Object key) Gets the previous key before the one specified.Puts the key-value pair into the map, replacing any previous pair.void
removeValue
(Object value) Removes the key-value pair that is currently mapped to the specified value (optional operation).int
size()
toString()
values()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
main
The parent map. -
keySet
Store the keySet once created. -
valuesSet
Store the valuesSet once created. -
entrySet
Store the entrySet once created.
-
-
Constructor Details
-
Inverse
Inverse(TreeBidiMap main) Constructor.- Parameters:
main
- the main map
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
get
-
getKey
Description copied from interface:BidiMap
Gets the key that is currently mapped to the specified value.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)
. -
containsKey
- Specified by:
containsKey
in interfaceMap
-
containsValue
- Specified by:
containsValue
in interfaceMap
-
firstKey
Description copied from interface:OrderedMap
Gets the first key currently in this map.- Specified by:
firstKey
in interfaceOrderedMap
- Returns:
- the first key currently in this map
-
lastKey
Description copied from interface:OrderedMap
Gets the last key currently in this map.- Specified by:
lastKey
in interfaceOrderedMap
- Returns:
- the last key currently in this map
-
nextKey
Description copied from interface:OrderedMap
Gets the next key after the one specified.- Specified by:
nextKey
in interfaceOrderedMap
- Parameters:
key
- the key to search for next from- Returns:
- the next key, null if no match or at end
-
previousKey
Description copied from interface:OrderedMap
Gets the previous key before the one specified.- Specified by:
previousKey
in interfaceOrderedMap
- Parameters:
key
- the key to search for previous from- Returns:
- the previous key, null if no match or at start
-
put
Description copied from interface:BidiMap
Puts the key-value pair into the map, replacing any previous pair.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
-
putAll
-
remove
-
removeValue
Description copied from interface:BidiMap
Removes the key-value pair that is currently mapped to the specified value (optional operation).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)
.- Specified by:
removeValue
in interfaceBidiMap
- Parameters:
value
- the value to find the key-value pair for- Returns:
- the key that was removed,
null
if nothing removed
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
mapIterator
Description copied from interface:BidiMap
Obtains aMapIterator
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"); }
- Specified by:
mapIterator
in interfaceBidiMap
- Specified by:
mapIterator
in interfaceIterableMap
- Returns:
- a map iterator
-
orderedMapIterator
Description copied from interface:OrderedMap
Obtains anOrderedMapIterator
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(); }
- Specified by:
orderedMapIterator
in interfaceOrderedMap
- Returns:
- a map iterator
-
inverseBidiMap
Description copied from interface:OrderedBidiMap
Gets a view of this map where the keys and values are reversed.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 toinverseOrderedBidiMap()
.- Specified by:
inverseBidiMap
in interfaceBidiMap
- Specified by:
inverseBidiMap
in interfaceOrderedBidiMap
- Returns:
- an inverted bidirectional map
-
inverseOrderedBidiMap
Description copied from interface:OrderedBidiMap
Gets a view of this map where the keys and values are reversed.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.- Specified by:
inverseOrderedBidiMap
in interfaceOrderedBidiMap
- Returns:
- an inverted bidirectional map
-
equals
-
hashCode
public int hashCode() -
toString
-