Class TreeBidiMap.Inverse
- All Implemented Interfaces:
Map<V,
,K> BidiMap<V,
,K> Get<V,
,K> IterableGet<V,
,K> IterableMap<V,
,K> OrderedBidiMap<V,
,K> OrderedMap<V,
,K> Put<V,
K>
- Enclosing class:
TreeBidiMap<K extends Comparable<K>,
V extends Comparable<V>>
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionStore the entrySet once created.Store the keySet once created.Store the valuesSet once created. -
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.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.previousKey
(V 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()
Returns aSet
view of the values contained in this map.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
-
inverseKeySet
Store the keySet once created. -
inverseValuesSet
Store the valuesSet once created. -
inverseEntrySet
Store the entrySet once created.
-
-
Constructor Details
-
Inverse
Inverse()
-
-
Method Details
-
size
public int size()- Specified by:
size
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
size
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Returns:
- the number of key-value mappings in this map
- See Also:
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
isEmpty
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Returns:
true
if this map contains no key-value mappings- See Also:
-
get
- Specified by:
get
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
get
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
null
if this map contains no mapping for the key - See Also:
-
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)
.- Specified by:
getKey
in interfaceBidiMap<V extends Comparable<V>,
K extends Comparable<K>> - Parameters:
value
- the value to find the key for- Returns:
- the mapped key, or
null
if not found
-
containsKey
- Specified by:
containsKey
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
containsKey
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Parameters:
key
- key whose presence in this map is to be tested- Returns:
true
if this map contains a mapping for the specified key- See Also:
-
containsValue
- Specified by:
containsValue
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
containsValue
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Parameters:
value
- value whose presence in this map is to be tested- Returns:
true
if this map maps one or more keys to the specified value- See Also:
-
firstKey
Description copied from interface:OrderedMap
Gets the first key currently in this map.- Specified by:
firstKey
in interfaceOrderedMap<V extends Comparable<V>,
K extends Comparable<K>> - 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<V extends Comparable<V>,
K extends Comparable<K>> - 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<V extends Comparable<V>,
K extends Comparable<K>> - 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<V extends Comparable<V>,
K extends Comparable<K>> - 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
- Specified by:
put
in interfaceBidiMap<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
put
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
put
in interfacePut<V extends Comparable<V>,
K extends Comparable<K>> - Parameters:
key
- the key to storevalue
- the value to store- Returns:
- the previous value mapped to this key
- See Also:
-
putAll
- Specified by:
putAll
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
putAll
in interfacePut<V extends Comparable<V>,
K extends Comparable<K>> - Parameters:
map
- mappings to be stored in this map- See Also:
-
remove
- Specified by:
remove
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
remove
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Parameters:
key
- key whose mapping is to be removed from the map- Returns:
- the previous value associated with
key
, ornull
if there was no mapping forkey
. - See Also:
-
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<V extends Comparable<V>,
K extends Comparable<K>> - 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()- Specified by:
clear
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
clear
in interfacePut<V extends Comparable<V>,
K extends Comparable<K>> - See Also:
-
keySet
- Specified by:
keySet
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
keySet
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Returns:
- a set view of the keys contained in this map
- See Also:
-
values
Description copied from interface:BidiMap
Returns aSet
view of the values contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremove
operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove
,Collection.remove
,removeAll
,retainAll
andclear
operations. It does not support theadd
oraddAll
operations.- Specified by:
values
in interfaceBidiMap<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
values
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
values
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Returns:
- a set view of the values contained in this map
- See Also:
-
entrySet
- Specified by:
entrySet
in interfaceGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
entrySet
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Returns:
- a set view of the mappings contained in this map
- See Also:
-
mapIterator
Description copied from interface:IterableGet
Obtains aMapIterator
over the map.A map iterator is an efficient way of iterating over maps. There is no need to access the entry set or use Map Entry objects.
IterableMap<String,Integer> map = new HashedMap<String,Integer>(); MapIterator<String,Integer> it = map.mapIterator(); while (it.hasNext()) { String key = it.next(); Integer value = it.getValue(); it.setValue(value + 1); }
- Specified by:
mapIterator
in interfaceIterableGet<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
mapIterator
in interfaceOrderedMap<V extends Comparable<V>,
K extends Comparable<K>> - 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<V extends Comparable<V>,
K extends Comparable<K>> - Specified by:
inverseBidiMap
in interfaceOrderedBidiMap<V extends Comparable<V>,
K extends Comparable<K>> - Returns:
- an inverted bidirectional map
-
equals
- Specified by:
equals
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Overrides:
equals
in classObject
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceMap<V extends Comparable<V>,
K extends Comparable<K>> - Overrides:
hashCode
in classObject
-
toString
-