public abstract class AbstractDualBidiMap<K,V> extends java.lang.Object implements BidiMap<K,V>
BidiMap
implemented using two maps.
An implementation can be written simply by implementing the
createBidiMap(Map, Map, BidiMap)
method.
DualHashBidiMap
,
DualTreeBidiMap
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<K,V>> |
entrySet()
Gets an entrySet view of the map.
|
boolean |
equals(java.lang.Object obj) |
V |
get(java.lang.Object key) |
K |
getKey(java.lang.Object value)
Gets the key that is currently mapped to the specified value.
|
int |
hashCode() |
BidiMap<V,K> |
inverseBidiMap()
Gets a view of this map where the keys and values are reversed.
|
boolean |
isEmpty() |
java.util.Set<K> |
keySet()
Gets a keySet view of the map.
|
MapIterator<K,V> |
mapIterator()
Obtains a
MapIterator over the map. |
V |
put(K key,
V value)
Puts the key-value pair into the map, replacing any previous pair.
|
void |
putAll(java.util.Map<? extends K,? extends V> map) |
V |
remove(java.lang.Object key) |
K |
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<V> |
values()
Gets a values view of the map.
|
public V get(java.lang.Object key)
public int size()
public boolean isEmpty()
public boolean containsKey(java.lang.Object key)
public boolean equals(java.lang.Object obj)
public int hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
public V put(K key, V 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 V remove(java.lang.Object key)
public void clear()
public boolean containsValue(java.lang.Object value)
public MapIterator<K,V> mapIterator()
MapIterator
over the map.
The iterator implements ResetableMapIterator
.
This implementation relies on the entrySet iterator.
The setValue() methods only allow a new value to be set. If the value being set is already in the map, an IllegalArgumentException is thrown (as setValue cannot change the size of the map).
mapIterator
in interface IterableGet<K,V>
public K 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 K 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<K,V>
value
- the value to find the key-value pair fornull
if nothing removedpublic BidiMap<V,K> inverseBidiMap()
BidiMap
Changes to one map will be visible in the other and vice versa.
This enables both directions of the map to be accessed as a Map
.
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.
inverseBidiMap
in interface BidiMap<K,V>
public java.util.Set<K> keySet()
public java.util.Set<V> values()
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
The Map Entry setValue() method only allow a new value to be set. If the value being set is already in the map, an IllegalArgumentException is thrown (as setValue cannot change the size of the map).
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"