public final class EnumHashBiMap<K extends java.lang.Enum<K>,V> extends AbstractBiMap<K,V>
BiMap
backed by an EnumMap
instance for keys-to-values, and a HashMap
instance for values-to-keys. Null keys are not permitted, but null values are. An EnumHashBiMap
and its inverse are both serializable.
See the Guava User Guide article on BiMap
.
AbstractBiMap.BiMapEntry, AbstractBiMap.Inverse<K,V>
ForwardingMap.StandardEntrySet, ForwardingMap.StandardKeySet, ForwardingMap.StandardValues
Modifier and Type | Field and Description |
---|---|
private java.lang.Class<K> |
keyType |
private static long |
serialVersionUID |
inverse
Modifier | Constructor and Description |
---|---|
private |
EnumHashBiMap(java.lang.Class<K> keyType) |
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.
|
static <K extends java.lang.Enum<K>,V> |
create(java.lang.Class<K> keyType)
Returns a new, empty
EnumHashBiMap using the specified key type. |
static <K extends java.lang.Enum<K>,V> |
create(java.util.Map<K,? extends V> map)
Constructs a new bimap with the same mappings as the specified map.
|
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. |
java.lang.Class<K> |
keyType()
Returns the associated key type.
|
V |
put(K key,
V value) |
private void |
readObject(java.io.ObjectInputStream stream) |
private void |
writeObject(java.io.ObjectOutputStream stream) |
checkValue, clear, containsValue, delegate, entrySet, entrySetIterator, inverse, keySet, makeInverse, putAll, remove, replaceAll, setDelegates, setInverse, values
containsKey, equals, get, hashCode, isEmpty, size, standardClear, standardContainsKey, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToString
toString
private static final long serialVersionUID
private EnumHashBiMap(java.lang.Class<K> keyType)
public static <K extends java.lang.Enum<K>,V> EnumHashBiMap<K,V> create(java.lang.Class<K> keyType)
EnumHashBiMap
using the specified key type.keyType
- the key typepublic static <K extends java.lang.Enum<K>,V> EnumHashBiMap<K,V> create(java.util.Map<K,? extends V> map)
EnumHashBiMap
or an EnumBiMap
, the new bimap has the same key type as the input
bimap. Otherwise, the specified map must contain at least one mapping, in order to determine
the key type.map
- the map whose mappings are to be placed in this mapjava.lang.IllegalArgumentException
- if map is not an EnumBiMap
or an EnumHashBiMap
instance and contains no mappingsK checkKey(K key)
AbstractBiMap
checkKey
in class AbstractBiMap<K extends java.lang.Enum<K>,V>
public V forcePut(K key, V value)
BiMap
put
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 extends java.lang.Enum<K>,V>
forcePut
in class AbstractBiMap<K extends java.lang.Enum<K>,V>
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keynull
, or
null
if there was no previous entrypublic java.lang.Class<K> keyType()
private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException