Class SingleElementListIterable<E>

  • Type Parameters:
    E - the type of elements returned by the list iterable's list iterator
    All Implemented Interfaces:
    java.lang.Iterable<E>, ListIterable<E>

    public class SingleElementListIterable<E>
    extends java.lang.Object
    implements ListIterable<E>
    A SingleElementListIterable returns a ListIterator that holds a single element and returns it with the first call to ListIterator.next(), at which point it will return false to any subsequent call to ListIterator.hasNext(). Likewise, it will return false to a call to ListIterator.hasPrevious() until a call to ListIterator.next(), at which point a call to ListIterator.previous() will return the single element.

    A SingleElementListIterable is equivalent to the Iterable returned by: Collections.singletonList(Object).

    See Also:
    SingleElementListIterator, SingleElementListIterable
    • Constructor Summary

      Constructors 
      Constructor Description
      SingleElementListIterable​(E element)
      Construct a list iterable that contains only the specified element.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.ListIterator<E> iterator()
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • SingleElementListIterable

        public SingleElementListIterable​(E element)
        Construct a list iterable that contains only the specified element.
    • Method Detail

      • iterator

        public java.util.ListIterator<E> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface ListIterable<E>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object