Class SingletonImmutableSet<E>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

    final class SingletonImmutableSet<E>
    extends ImmutableSet<E>
    Implementation of ImmutableSet with exactly one element.
    • Field Detail

      • element

        final transient E element
      • cachedHashCode

        private transient int cachedHashCode
    • Constructor Detail

      • SingletonImmutableSet

        SingletonImmutableSet​(E element)
      • SingletonImmutableSet

        SingletonImmutableSet​(E element,
                              int hashCode)
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • contains

        public boolean contains​(java.lang.Object target)
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Set<E>
        Specified by:
        contains in class ImmutableCollection<E>
      • iterator

        public UnmodifiableIterator<E> iterator()
        Description copied from class: ImmutableCollection
        Returns an unmodifiable iterator across the elements in this collection.
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class ImmutableSet<E>
      • isPartialView

        boolean isPartialView()
        Description copied from class: ImmutableCollection
        Returns true if this immutable collection's implementation contains references to user-created objects that aren't accessible via this collection's methods. This is generally used to determine whether copyOf implementations should make an explicit copy to avoid memory leaks.
        Specified by:
        isPartialView in class ImmutableCollection<E>
      • copyIntoArray

        int copyIntoArray​(java.lang.Object[] dst,
                          int offset)
        Description copied from class: ImmutableCollection
        Copies the contents of this immutable collection into the specified array at the specified offset. Returns offset + size().
        Overrides:
        copyIntoArray in class ImmutableCollection<E>
      • hashCode

        public final int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface java.util.Set<E>
        Overrides:
        hashCode in class ImmutableSet<E>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractCollection<E>