abstract class AbstractBiMap<K,V> extends ForwardingMap<K,V> implements BiMap<K,V>, java.io.Serializable
Map instances.
Note that this class contains equals() calls that keep it from supporting IdentityHashMap backing maps.
| Modifier and Type | Class and Description |
|---|---|
(package private) class |
AbstractBiMap.BiMapEntry |
private class |
AbstractBiMap.EntrySet |
(package private) static class |
AbstractBiMap.Inverse<K,V>
The inverse of any other
AbstractBiMap subclass. |
private class |
AbstractBiMap.KeySet |
private class |
AbstractBiMap.ValueSet |
ForwardingMap.StandardEntrySet, ForwardingMap.StandardKeySet, ForwardingMap.StandardValues| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<K,V> |
delegate |
private java.util.Set<java.util.Map.Entry<K,V>> |
entrySet |
(package private) AbstractBiMap<V,K> |
inverse |
private java.util.Set<K> |
keySet |
private static long |
serialVersionUID |
private java.util.Set<V> |
valueSet |
| Modifier | Constructor and Description |
|---|---|
private |
AbstractBiMap(java.util.Map<K,V> backward,
AbstractBiMap<V,K> forward)
Private constructor for inverse bimap.
|
(package private) |
AbstractBiMap(java.util.Map<K,V> forward,
java.util.Map<V,K> backward)
Package-private constructor for creating a map-backed bimap.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) K |
checkKey(K key)
Returns its input, or throws an exception if this is not a valid key.
|
(package private) V |
checkValue(V value)
Returns its input, or throws an exception if this is not a valid value.
|
void |
clear() |
boolean |
containsValue(java.lang.Object value) |
protected java.util.Map<K,V> |
delegate()
Returns the backing delegate instance that methods are forwarded to.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
(package private) java.util.Iterator<java.util.Map.Entry<K,V>> |
entrySetIterator() |
V |
forcePut(K key,
V value)
An alternate form of
put that silently removes any existing entry with the value value before proceeding with the BiMap.put(K, V) operation. |
BiMap<V,K> |
inverse()
Returns the inverse view of this bimap, which maps each of this bimap's values to its
associated key.
|
java.util.Set<K> |
keySet() |
(package private) AbstractBiMap<V,K> |
makeInverse(java.util.Map<V,K> backward) |
V |
put(K key,
V value) |
void |
putAll(java.util.Map<? extends K,? extends V> map) |
private V |
putInBothMaps(K key,
V value,
boolean force) |
V |
remove(java.lang.Object key) |
private V |
removeFromBothMaps(java.lang.Object key) |
private void |
removeFromInverseMap(V oldValue) |
void |
replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function) |
(package private) void |
setDelegates(java.util.Map<K,V> forward,
java.util.Map<V,K> backward)
Specifies the delegate maps going in each direction.
|
(package private) void |
setInverse(AbstractBiMap<V,K> inverse) |
private void |
updateInverseMap(K key,
boolean containedKey,
V oldValue,
V newValue) |
java.util.Set<V> |
values() |
containsKey, equals, get, hashCode, isEmpty, size, standardClear, standardContainsKey, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToStringtoStringtransient AbstractBiMap<V,K> inverse
@CheckForNull private transient java.util.Set<K> keySet
@CheckForNull private transient java.util.Set<V> valueSet
private static final long serialVersionUID
AbstractBiMap(java.util.Map<K,V> forward, java.util.Map<V,K> backward)
private AbstractBiMap(java.util.Map<K,V> backward, AbstractBiMap<V,K> forward)
protected java.util.Map<K,V> delegate()
ForwardingObjectForwardingSet.delegate(). Concrete subclasses override this method to supply the
instance being decorated.delegate in class ForwardingMap<K,V>V checkValue(V value)
void setDelegates(java.util.Map<K,V> forward, java.util.Map<V,K> backward)
AbstractBiMap<V,K> makeInverse(java.util.Map<V,K> backward)
void setInverse(AbstractBiMap<V,K> inverse)
public boolean containsValue(@CheckForNull
java.lang.Object value)
containsValue in interface java.util.Map<K,V>containsValue in class ForwardingMap<K,V>@CheckForNull public V forcePut(K key, V value)
BiMapput that silently removes any existing entry with the value value before proceeding with the BiMap.put(K, V) operation. If the bimap previously contained the
provided key-value mapping, this method has no effect.
Note that a successful call to this method could cause the size of the bimap to increase by one, stay the same, or even decrease by one.
Warning: If an existing entry with this value is removed, the key for that entry is discarded and not returned.
forcePut in interface BiMap<K,V>key - the key with which the specified value is to be associatedvalue - the value to be associated with the specified keynull if there was no
previous entry. (If the bimap contains null values, then forcePut, like put, returns null both if the key is absent and if it is present with a null
value.)private void updateInverseMap(K key, boolean containedKey, @CheckForNull V oldValue, V newValue)
@CheckForNull public V remove(@CheckForNull java.lang.Object key)
private V removeFromBothMaps(@CheckForNull java.lang.Object key)
private void removeFromInverseMap(V oldValue)
public void putAll(java.util.Map<? extends K,? extends V> map)
BiMapWarning: the results of calling this method may vary depending on the iteration order
of map.
public void replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)
public void clear()
public BiMap<V,K> inverse()
BiMapNote:There is no guaranteed correspondence between the iteration order of a bimap and that of its inverse.
public java.util.Set<K> keySet()
public java.util.Set<V> values()
BiMapBecause a bimap has unique values, this method returns a Set, instead of the Collection specified in the Map interface.