class TreeBidiMap.Inverse extends java.lang.Object implements OrderedBidiMap<V,K>
Modifier and Type | Field and Description |
---|---|
private java.util.Set<java.util.Map.Entry<V,K>> |
inverseEntrySet
Store the entrySet once created.
|
private java.util.Set<V> |
inverseKeySet
Store the keySet once created.
|
private java.util.Set<K> |
inverseValuesSet
Store the valuesSet once created.
|
Constructor and Description |
---|
Inverse() |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<V,K>> |
entrySet() |
boolean |
equals(java.lang.Object obj) |
V |
firstKey()
Gets the first key currently in this map.
|
K |
get(java.lang.Object key) |
V |
getKey(java.lang.Object value)
Gets the key that is currently mapped to the specified value.
|
int |
hashCode() |
OrderedBidiMap<K,V> |
inverseBidiMap()
Gets a view of this map where the keys and values are reversed.
|
boolean |
isEmpty() |
java.util.Set<V> |
keySet() |
V |
lastKey()
Gets the last key currently in this map.
|
OrderedMapIterator<V,K> |
mapIterator()
Obtains a
MapIterator over the map. |
V |
nextKey(V key)
Gets the next key after the one specified.
|
V |
previousKey(V key)
Gets the previous key before the one specified.
|
K |
put(V key,
K value)
Puts the key-value pair into the map, replacing any previous pair.
|
void |
putAll(java.util.Map<? extends V,? extends K> map) |
K |
remove(java.lang.Object key) |
V |
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.Set<K> |
values()
Returns a
Set view of the values contained in this map. |
private java.util.Set<V extends java.lang.Comparable<V>> inverseKeySet
private java.util.Set<K extends java.lang.Comparable<K>> inverseValuesSet
public int size()
public boolean isEmpty()
isEmpty
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
isEmpty
in interface Get<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
true
if this map contains no key-value mappingsMap.isEmpty()
public K get(java.lang.Object key)
get
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
get
in interface Get<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
key
- the key whose associated value is to be returnednull
if this map contains no mapping for the keyMap.get(Object)
public V 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<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
containsKey
in interface Get<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
key
- key whose presence in this map is to be testedtrue
if this map contains a mapping for the specified
keyMap.containsKey(Object)
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
containsValue
in interface Get<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
value
- value whose presence in this map is to be testedtrue
if this map maps one or more keys to the
specified valueMap.containsValue(Object)
public V firstKey()
OrderedMap
public V lastKey()
OrderedMap
public V nextKey(V key)
OrderedMap
public V previousKey(V key)
OrderedMap
previousKey
in interface OrderedMap<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
key
- the key to search for previous frompublic K put(V key, K 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
put
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
put
in interface BidiMap<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
put
in interface Put<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
key
- the key to storevalue
- the value to storeMap.put(Object, Object)
public void putAll(java.util.Map<? extends V,? extends K> map)
putAll
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
putAll
in interface Put<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
map
- mappings to be stored in this mapMap.putAll(Map)
public K remove(java.lang.Object key)
remove
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
remove
in interface Get<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
key
- key whose mapping is to be removed from the mapkey
, or
null
if there was no mapping for key
.Map.remove(Object)
public V 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)
.
public void clear()
public java.util.Set<V> keySet()
keySet
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
keySet
in interface Get<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
Map.keySet()
public java.util.Set<K> values()
BidiMap
Set
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 own
remove
operation), the results of the iteration are undefined.
The set supports element removal, which removes the corresponding
mapping from the map, via the Iterator.remove
,
Collection.remove
, removeAll
,
retainAll
and clear
operations. It does not
support the add
or addAll
operations.values
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
values
in interface BidiMap<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
values
in interface Get<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
Map.values()
public java.util.Set<java.util.Map.Entry<V,K>> entrySet()
entrySet
in interface java.util.Map<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
entrySet
in interface Get<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
Map.entrySet()
public OrderedMapIterator<V,K> mapIterator()
IterableGet
MapIterator
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); }
mapIterator
in interface IterableGet<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
mapIterator
in interface OrderedMap<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
public OrderedBidiMap<K,V> 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<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
inverseBidiMap
in interface OrderedBidiMap<V extends java.lang.Comparable<V>,K extends java.lang.Comparable<K>>
public boolean equals(java.lang.Object obj)
public int hashCode()
public java.lang.String toString()
toString
in class java.lang.Object