Class SimpleIterator<T>

  • Type Parameters:
    T - The type of elements yielded by this iterator.
    All Implemented Interfaces:
    Iterator<T>

    public abstract class SimpleIterator<T>
    extends Object
    implements Iterator<T>
    SimpleIterator offers an easier way to implement the Iterator interface, by requiring only one method, nextIfAvailable(), to be implemented instead of both hasNext() and next(). In addition, implementations are free to throw any exception, which, if is a checked exception, will be rethrown wrapped in a RuntimeException.
    See Also:
    nextIfAvailable()
    • Constructor Detail

      • SimpleIterator

        public SimpleIterator()
    • Method Detail

      • nextIfAvailable

        protected abstract Optional<? extends T> nextIfAvailable()
                                                          throws Exception
        Returns:
        The next element if any, or empty if there are no more elements.
        Throws:
        Exception
      • hasNext

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

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

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