Class TreeBidiMap.Inverse
- java.lang.Object
-
- org.apache.commons.collections4.bidimap.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>>
class TreeBidiMap.Inverse extends Object implements OrderedBidiMap<V,K>
The inverse map implementation.
-
-
Constructor Summary
Constructors Constructor Description Inverse()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<V,K>>entrySet()booleanequals(Object obj)VfirstKey()Gets the first key currently in this map.Kget(Object key)VgetKey(Object value)Gets the key that is currently mapped to the specified value.inthashCode()OrderedBidiMap<K,V>inverseBidiMap()Gets a view of this map where the keys and values are reversed.booleanisEmpty()Set<V>keySet()VlastKey()Gets the last key currently in this map.OrderedMapIterator<V,K>mapIterator()Obtains aMapIteratorover the map.VnextKey(V key)Gets the next key after the one specified.VpreviousKey(V key)Gets the previous key before the one specified.Kput(V key, K value)Puts the key-value pair into the map, replacing any previous pair.voidputAll(Map<? extends V,? extends K> map)Kremove(Object key)VremoveValue(Object value)Removes the key-value pair that is currently mapped to the specified value (optional operation).intsize()StringtoString()Set<K>values()Returns aSetview 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
-
-
-
-
Method Detail
-
size
public int size()
- Specified by:
sizein interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
sizein interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
- the number of key-value mappings in this map
- See Also:
Map.size()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
isEmptyin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
trueif this map contains no key-value mappings- See Also:
Map.isEmpty()
-
get
public K get(Object key)
- Specified by:
getin interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
getin 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
nullif this map contains no mapping for the key - See Also:
Map.get(Object)
-
getKey
public V getKey(Object value)
Description copied from interface:BidiMapGets the key that is currently mapped to the specified value.If the value is not contained in the map,
nullis returned.Implementations should seek to make this method perform equally as well as
get(Object).- Specified by:
getKeyin interfaceBidiMap<V extends Comparable<V>,K extends Comparable<K>>- Parameters:
value- the value to find the key for- Returns:
- the mapped key, or
nullif not found
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
containsKeyin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key- See Also:
Map.containsKey(Object)
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
containsValuein interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Parameters:
value- value whose presence in this map is to be tested- Returns:
trueif this map maps one or more keys to the specified value- See Also:
Map.containsValue(Object)
-
firstKey
public V firstKey()
Description copied from interface:OrderedMapGets the first key currently in this map.- Specified by:
firstKeyin interfaceOrderedMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
- the first key currently in this map
-
lastKey
public V lastKey()
Description copied from interface:OrderedMapGets the last key currently in this map.- Specified by:
lastKeyin interfaceOrderedMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
- the last key currently in this map
-
nextKey
public V nextKey(V key)
Description copied from interface:OrderedMapGets the next key after the one specified.- Specified by:
nextKeyin 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
public V previousKey(V key)
Description copied from interface:OrderedMapGets the previous key before the one specified.- Specified by:
previousKeyin 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
public K put(V key, K value)
Description copied from interface:BidiMapPuts 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:
putin interfaceBidiMap<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
putin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
putin 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:
Map.put(Object, Object)
-
putAll
public void putAll(Map<? extends V,? extends K> map)
- Specified by:
putAllin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
putAllin interfacePut<V extends Comparable<V>,K extends Comparable<K>>- Parameters:
map- mappings to be stored in this map- See Also:
Map.putAll(Map)
-
remove
public K remove(Object key)
- Specified by:
removein interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
removein 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, ornullif there was no mapping forkey. - See Also:
Map.remove(Object)
-
removeValue
public V removeValue(Object value)
Description copied from interface:BidiMapRemoves the key-value pair that is currently mapped to the specified value (optional operation).If the value is not contained in the map,
nullis returned.Implementations should seek to make this method perform equally as well as
remove(Object).- Specified by:
removeValuein 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,
nullif nothing removed
-
clear
public void clear()
- Specified by:
clearin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
clearin interfacePut<V extends Comparable<V>,K extends Comparable<K>>- See Also:
Map.clear()
-
keySet
public Set<V> keySet()
- Specified by:
keySetin interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
keySetin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
- a set view of the keys contained in this map
- See Also:
Map.keySet()
-
values
public Set<K> values()
Description copied from interface:BidiMapReturns aSetview 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 ownremoveoperation), 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,retainAllandclearoperations. It does not support theaddoraddAlloperations.- Specified by:
valuesin interfaceBidiMap<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
valuesin interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
valuesin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
- a set view of the values contained in this map
- See Also:
Map.values()
-
entrySet
public Set<Map.Entry<V,K>> entrySet()
- Specified by:
entrySetin interfaceGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
entrySetin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
- a set view of the mappings contained in this map
- See Also:
Map.entrySet()
-
mapIterator
public OrderedMapIterator<V,K> mapIterator()
Description copied from interface:IterableGetObtains aMapIteratorover 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:
mapIteratorin interfaceIterableGet<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
mapIteratorin interfaceOrderedMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
- a map iterator
-
inverseBidiMap
public OrderedBidiMap<K,V> inverseBidiMap()
Description copied from interface:OrderedBidiMapGets 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
OrderedBidiMapinstance, usually by forwarding toinverseOrderedBidiMap().- Specified by:
inverseBidiMapin interfaceBidiMap<V extends Comparable<V>,K extends Comparable<K>>- Specified by:
inverseBidiMapin interfaceOrderedBidiMap<V extends Comparable<V>,K extends Comparable<K>>- Returns:
- an inverted bidirectional map
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceMap<V extends Comparable<V>,K extends Comparable<K>>- Overrides:
hashCodein classObject
-
-