Class SingletonImmutableList<E>

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

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

      • element

        final transient E element
    • Constructor Detail

      • SingletonImmutableList

        SingletonImmutableList​(E element)
    • Method Detail

      • get

        public E get​(int index)
      • 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.List<E>
        Overrides:
        iterator in class ImmutableList<E>
      • spliterator

        public java.util.Spliterator<E> spliterator()
        Specified by:
        spliterator in interface java.util.Collection<E>
        Specified by:
        spliterator in interface java.lang.Iterable<E>
        Specified by:
        spliterator in interface java.util.List<E>
        Overrides:
        spliterator in class ImmutableList<E>
      • size

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

        public ImmutableList<E> subList​(int fromIndex,
                                        int toIndex)
        Description copied from class: ImmutableList
        Returns an immutable list of the elements between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the empty immutable list is returned.)
        Specified by:
        subList in interface java.util.List<E>
        Overrides:
        subList in class ImmutableList<E>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractCollection<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>