Class NextOnlyIterator<T>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    java.util.Iterator<T>

    public abstract class NextOnlyIterator<T>
    extends java.lang.Object
    implements java.util.Iterator<T>
    Creating things that act like iterators is annoying because the programmer has to supply implementations of the hasNext() and next() methods. This class is similar to the GUAVA AbstractIterator.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void generateNext()
      This method will be called by the iterator whenever it needs to find the next element to be iterated over.
      boolean hasNext()  
      T next()  
      protected void nextElement​(T el)
      Call this from generateNext() with the next element to be returned from the iterator.
      protected void noMoreElements()
      Call this from generateNext() if there are no more elements to be iterated over.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
    • Constructor Detail

      • NextOnlyIterator

        public NextOnlyIterator()
    • Method Detail

      • hasNext

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

        public T next()
        Specified by:
        next in interface java.util.Iterator<T>
      • generateNext

        protected abstract void generateNext()
        This method will be called by the iterator whenever it needs to find the next element to be iterated over. Each time generateNext() is called, it should call nextElement() or noMoreElements() as appropriate.
      • nextElement

        protected void nextElement​(T el)
        Call this from generateNext() with the next element to be returned from the iterator.
        Parameters:
        el -
      • noMoreElements

        protected void noMoreElements()
        Call this from generateNext() if there are no more elements to be iterated over.