Class SingleElementIterator<E>

  • Type Parameters:
    E - The generic type of the iterator.
    All Implemented Interfaces:
    Iterable<E>, Iterator<E>

    public final class SingleElementIterator<E>
    extends Object
    implements Iterator<E>, Iterable<E>
    An Iterator that contains only a single element. The element can be reset such that the iterator can be used multiple times. Initially, the iterator is empty until an element is set via set(Object).
    • Constructor Detail

      • SingleElementIterator

        public SingleElementIterator()
    • Method Detail

      • set

        public void set​(E current)
        Resets the element. After this call, the iterator has one element available, which is the given element.
        Parameters:
        current - The element to make available to the iterator.
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface Iterator<E>
      • next

        public E next()
        Specified by:
        next in interface Iterator<E>
      • remove

        public void remove()
        Specified by:
        remove in interface Iterator<E>