Class SingletonImmutableBiMap<K,​V>

  • All Implemented Interfaces:
    BiMap<K,​V>, java.io.Serializable, java.util.Map<K,​V>

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

      • singleKey

        final transient K singleKey
      • singleValue

        final transient V singleValue
      • lazyInverse

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

      • SingletonImmutableBiMap

        SingletonImmutableBiMap​(K singleKey,
                                V singleValue)
      • SingletonImmutableBiMap

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

      • get

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

        public int size()
      • forEach

        public void forEach​(java.util.function.BiConsumer<? super K,​? super V> action)
      • containsKey

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

        public boolean containsValue​(@CheckForNull
                                     java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
        Overrides:
        containsValue 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