Class SingleElementListIterator<E>

  • All Implemented Interfaces:
    java.util.Iterator<E>, java.util.ListIterator<E>

    public class SingleElementListIterator<E>
    extends java.lang.Object
    implements java.util.ListIterator<E>
    A SingleElementListIterator holds a single element and returns it with the first call to next(), at which point it will return false to any subsequent call to hasNext(). Likewise, it will return false to a call to hasPrevious() until a call to next(), at which point a call to previous() will return the single element.
    Version:
    2.4
    Since:
    2.4
    • Constructor Detail

      • SingleElementListIterator

        public SingleElementListIterator​(E element)
        Creates a new SingleElementListIterator that returns only the specified element.
        Parameters:
        element - The only element of this Iterator
    • Method Detail

      • add

        public void add​(E item)
        Specified by:
        add in interface java.util.ListIterator<E>
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<E>
        Specified by:
        hasNext in interface java.util.ListIterator<E>
      • hasPrevious

        public boolean hasPrevious()
        Specified by:
        hasPrevious in interface java.util.ListIterator<E>
      • iterator

        public java.util.ListIterator<E> iterator()
      • next

        public E next()
        Specified by:
        next in interface java.util.Iterator<E>
        Specified by:
        next in interface java.util.ListIterator<E>
      • nextIndex

        public int nextIndex()
        Specified by:
        nextIndex in interface java.util.ListIterator<E>
      • previous

        public E previous()
        Specified by:
        previous in interface java.util.ListIterator<E>
      • previousIndex

        public int previousIndex()
        Specified by:
        previousIndex in interface java.util.ListIterator<E>
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<E>
        Specified by:
        remove in interface java.util.ListIterator<E>
      • set

        public void set​(E item)
        Specified by:
        set in interface java.util.ListIterator<E>
      • toString

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