Class SingletonImmutableBiMap<K,V>

java.lang.Object
com.google.common.collect.ImmutableMap<K,V>
com.google.common.collect.ImmutableBiMap<K,V>
com.google.common.collect.SingletonImmutableBiMap<K,V>
All Implemented Interfaces:
BiMap<K,V>, Serializable, Map<K,V>

final class SingletonImmutableBiMap<K,V> extends ImmutableBiMap<K,V>
Implementation of ImmutableMap with exactly one entry.
  • Field Details

    • singleKey

      final transient K singleKey
    • singleValue

      final transient V singleValue
    • inverse

      @CheckForNull private final transient ImmutableBiMap<V,K> inverse
    • lazyInverse

      @CheckForNull private transient ImmutableBiMap<V,K> lazyInverse
  • Constructor Details

    • SingletonImmutableBiMap

      SingletonImmutableBiMap(K singleKey, V singleValue)
    • SingletonImmutableBiMap

      private SingletonImmutableBiMap(K singleKey, V singleValue, ImmutableBiMap<V,K> inverse)
  • Method Details

    • get

      @CheckForNull public V get(@CheckForNull Object key)
      Specified by:
      get in interface Map<K,V>
      Specified by:
      get in class ImmutableMap<K,V>
    • size

      public int size()
    • forEach

      public void forEach(BiConsumer<? super K,? super V> action)
    • containsKey

      public boolean containsKey(@CheckForNull Object key)
      Specified by:
      containsKey in interface Map<K,V>
      Overrides:
      containsKey in class ImmutableMap<K,V>
    • containsValue

      public boolean containsValue(@CheckForNull Object value)
      Specified by:
      containsValue in interface Map<K,V>
      Overrides:
      containsValue in class ImmutableMap<K,V>
    • isPartialView

      boolean isPartialView()
      Specified by:
      isPartialView in class ImmutableMap<K,V>
    • createEntrySet

      ImmutableSet<Map.Entry<K,V>> createEntrySet()
      Specified by:
      createEntrySet in class ImmutableMap<K,V>
    • createKeySet

      ImmutableSet<K> createKeySet()
      Specified by:
      createKeySet in class ImmutableMap<K,V>
    • inverse

      public ImmutableBiMap<V,K> inverse()
      Description copied from class: ImmutableBiMap
      Returns the inverse view of this bimap, which maps each of this bimap's values to its associated key. The two bimaps are backed by the same data; any changes to one will appear in the other.

      Note:There is no guaranteed correspondence between the iteration order of a bimap and that of its inverse.

      The inverse of an ImmutableBiMap is another ImmutableBiMap.

      Specified by:
      inverse in interface BiMap<K,V>
      Specified by:
      inverse in class ImmutableBiMap<K,V>
      Returns:
      the inverse view of this bimap
    • writeReplace

      Object writeReplace()
      Description copied from class: ImmutableMap
      Returns a serializable form of this object. Non-public subclasses should not override this method. Publicly-accessible subclasses must override this method and should return a subclass of SerializedForm whose readResolve() method returns objects of the subclass type.
      Overrides:
      writeReplace in class ImmutableBiMap<K,V>