Package com.google.common.collect
Class EnumBiMap<K extends java.lang.Enum<K>,V extends java.lang.Enum<V>>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingMap<K,V>
-
- com.google.common.collect.AbstractBiMap<K,V>
-
- com.google.common.collect.EnumBiMap<K,V>
-
- All Implemented Interfaces:
BiMap<K,V>,java.io.Serializable,java.util.Map<K,V>
@GwtCompatible(emulated=true) public final class EnumBiMap<K extends java.lang.Enum<K>,V extends java.lang.Enum<V>> extends AbstractBiMap<K,V>
ABiMapbacked by twoEnumMapinstances. Null keys and values are not permitted. AnEnumBiMapand its inverse are both serializable.See the Guava User Guide article on
BiMap.- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.collect.AbstractBiMap
AbstractBiMap.BiMapEntry, AbstractBiMap.Inverse<K,V>
-
Nested classes/interfaces inherited from class com.google.common.collect.ForwardingMap
ForwardingMap.StandardEntrySet, ForwardingMap.StandardKeySet, ForwardingMap.StandardValues
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<K>keyTypeprivate static longserialVersionUIDprivate java.lang.Class<V>valueType-
Fields inherited from class com.google.common.collect.AbstractBiMap
inverse
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) KcheckKey(K key)Returns its input, or throws an exception if this is not a valid key.(package private) VcheckValue(V value)Returns its input, or throws an exception if this is not a valid value.static <K extends java.lang.Enum<K>,V extends java.lang.Enum<V>>
EnumBiMap<K,V>create(java.lang.Class<K> keyType, java.lang.Class<V> valueType)Returns a new, emptyEnumBiMapusing the specified key and value types.static <K extends java.lang.Enum<K>,V extends java.lang.Enum<V>>
EnumBiMap<K,V>create(java.util.Map<K,V> map)Returns a new bimap with the same mappings as the specified map.(package private) static <K extends java.lang.Enum<K>>
java.lang.Class<K>inferKeyType(java.util.Map<K,?> map)private static <V extends java.lang.Enum<V>>
java.lang.Class<V>inferValueType(java.util.Map<?,V> map)java.lang.Class<K>keyType()Returns the associated key type.private voidreadObject(java.io.ObjectInputStream stream)java.lang.Class<V>valueType()Returns the associated value type.private voidwriteObject(java.io.ObjectOutputStream stream)-
Methods inherited from class com.google.common.collect.AbstractBiMap
clear, containsValue, delegate, entrySet, entrySetIterator, forcePut, inverse, keySet, makeInverse, put, putAll, remove, replaceAll, setDelegates, setInverse, values
-
Methods inherited from class com.google.common.collect.ForwardingMap
containsKey, equals, get, hashCode, isEmpty, size, standardClear, standardContainsKey, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToString
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
Field Detail
-
serialVersionUID
@GwtIncompatible private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static <K extends java.lang.Enum<K>,V extends java.lang.Enum<V>> EnumBiMap<K,V> create(java.lang.Class<K> keyType, java.lang.Class<V> valueType)
Returns a new, emptyEnumBiMapusing the specified key and value types.- Parameters:
keyType- the key typevalueType- the value type
-
create
public static <K extends java.lang.Enum<K>,V extends java.lang.Enum<V>> EnumBiMap<K,V> create(java.util.Map<K,V> map)
Returns a new bimap with the same mappings as the specified map. If the specified map is anEnumBiMap, the new bimap has the same types as the provided map. Otherwise, the specified map must contain at least one mapping, in order to determine the key and value types.- Parameters:
map- the map whose mappings are to be placed in this map- Throws:
java.lang.IllegalArgumentException- if map is not anEnumBiMapinstance and contains no mappings
-
inferKeyType
static <K extends java.lang.Enum<K>> java.lang.Class<K> inferKeyType(java.util.Map<K,?> map)
-
inferValueType
private static <V extends java.lang.Enum<V>> java.lang.Class<V> inferValueType(java.util.Map<?,V> map)
-
keyType
public java.lang.Class<K> keyType()
Returns the associated key type.
-
valueType
public java.lang.Class<V> valueType()
Returns the associated value type.
-
checkKey
K checkKey(K key)
Description copied from class:AbstractBiMapReturns its input, or throws an exception if this is not a valid key.
-
checkValue
V checkValue(V value)
Description copied from class:AbstractBiMapReturns its input, or throws an exception if this is not a valid value.- Overrides:
checkValuein classAbstractBiMap<K extends java.lang.Enum<K>,V extends java.lang.Enum<V>>
-
writeObject
@GwtIncompatible private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException
- Throws:
java.io.IOException
-
readObject
@GwtIncompatible private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-