Class EnumBiMap<K extends java.lang.Enum<K>,​V extends java.lang.Enum<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>
    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:
    Serialized Form
    • Field Detail

      • keyType

        private transient java.lang.Class<K extends java.lang.Enum<K>> keyType
      • valueType

        private transient java.lang.Class<V extends java.lang.Enum<V>> valueType
    • Constructor Detail

      • EnumBiMap

        private EnumBiMap​(java.lang.Class<K> keyType,
                          java.lang.Class<V> valueType)
    • 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, empty EnumBiMap using the specified key and value types.
        Parameters:
        keyType - the key type
        valueType - 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 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:
        java.lang.IllegalArgumentException - if map is not an EnumBiMap instance 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: AbstractBiMap
        Returns its input, or throws an exception if this is not a valid key.
        Overrides:
        checkKey in class AbstractBiMap<K extends java.lang.Enum<K>,​V extends java.lang.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 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.IOException
        java.lang.ClassNotFoundException