Class EnumBiMap<K extends Enum<K>,V extends Enum<V>>

All Implemented Interfaces:
BiMap<K,V>, Serializable, Map<K,V>

public final class EnumBiMap<K extends Enum<K>,V extends Enum<V>> extends AbstractBiMap<K,V>
A BiMap backed by two EnumMap instances. Null keys and values are not permitted. An EnumBiMap and its inverse are both serializable.

See the Guava User Guide article on BiMap.

Since:
2.0
See Also:
  • Field Details

    • keyTypeOrObjectUnderJ2cl

      transient Class<K extends Enum<K>> keyTypeOrObjectUnderJ2cl
    • valueTypeOrObjectUnderJ2cl

      transient Class<V extends Enum<V>> valueTypeOrObjectUnderJ2cl
    • serialVersionUID

      private static final long serialVersionUID
      See Also:
  • Constructor Details

    • EnumBiMap

      private EnumBiMap(Class<K> keyTypeOrObjectUnderJ2cl, Class<V> valueTypeOrObjectUnderJ2cl)
  • Method Details

    • create

      public static <K extends Enum<K>, V extends Enum<V>> EnumBiMap<K,V> create(Class<K> keyType, Class<V> valueType)
      Returns a new, empty EnumBiMap using the specified key and value types.
      Parameters:
      keyType - the key type
      valueType - the value type
    • create

      public static <K extends Enum<K>, V extends Enum<V>> EnumBiMap<K,V> create(Map<K,V> map)
      Returns a new bimap with the same mappings as the specified map. If the specified map is an EnumBiMap, 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:
      IllegalArgumentException - if map is not an EnumBiMap instance and contains no mappings
    • inferKeyTypeOrObjectUnderJ2cl

      static <K extends Enum<K>> Class<K> inferKeyTypeOrObjectUnderJ2cl(Map<K,?> map)
    • inferValueTypeOrObjectUnderJ2cl

      private static <V extends Enum<V>> Class<V> inferValueTypeOrObjectUnderJ2cl(Map<?,V> map)
    • keyType

      public Class<K> keyType()
      Returns the associated key type.
    • valueType

      public Class<V> valueType()
      Returns the associated value type.
    • checkKey

      K checkKey(K key)
      Description copied from class: AbstractBiMap
      Returns its input, or throws an exception if this is not a valid key.
      Overrides:
      checkKey in class AbstractBiMap<K extends Enum<K>,V extends Enum<V>>
    • checkValue

      V checkValue(V value)
      Description copied from class: AbstractBiMap
      Returns its input, or throws an exception if this is not a valid value.
      Overrides:
      checkValue in class AbstractBiMap<K extends Enum<K>,V extends Enum<V>>
    • writeObject

      private void writeObject(ObjectOutputStream stream) throws IOException
      Throws:
      IOException
    • readObject

      private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException