public abstract class AbstractDualBidiMap extends java.lang.Object implements BidiMap
BidiMap
implemented using two maps.
An implementation can be written simply by implementing the
createMap
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 |
entrySet()
Gets an entrySet view of the map.
|
boolean |
equals(java.lang.Object obj) |
java.lang.Object |
get(java.lang.Object key) |
java.lang.Object |
getKey(java.lang.Object value)
Gets the key that is currently mapped to the specified value.
|
int |
hashCode() |
BidiMap |
inverseBidiMap()
Gets a view of this map where the keys and values are reversed.
|
boolean |
isEmpty() |
java.util.Set |
keySet()
Gets a keySet view of the map.
|
MapIterator |
mapIterator()
Obtains a
MapIterator over the map. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Puts the key-value pair into the map, replacing any previous pair.
|
void |
putAll(java.util.Map map) |
java.lang.Object |
remove(java.lang.Object key) |
java.lang.Object |
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.Collection |
values()
Gets a values view of the map.
|
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
public int size()
size
in interface java.util.Map
public boolean isEmpty()
isEmpty
in interface java.util.Map
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
public boolean equals(java.lang.Object obj)
equals
in interface java.util.Map
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Map
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object put(java.lang.Object key, java.lang.Object 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 void putAll(java.util.Map map)
putAll
in interface java.util.Map
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
public void clear()
clear
in interface java.util.Map
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
public MapIterator 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 BidiMap
mapIterator
in interface IterableMap
public java.lang.Object 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 java.lang.Object 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
value
- the value to find the key-value pair fornull
if nothing removedpublic BidiMap 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
public java.util.Set keySet()
keySet
in interface java.util.Map
public java.util.Collection values()
values
in interface java.util.Map
public java.util.Set 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).
entrySet
in interface java.util.Map
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"