Class PrefetchingIterator<T>

java.lang.Object
apoc.util.collection.PrefetchingIterator<T>
All Implemented Interfaces:
Iterator<T>
Direct Known Subclasses:
FilteringIterator, PrefetchingResourceIterator

public abstract class PrefetchingIterator<T> extends Object implements Iterator<T>
Abstract class for how you usually implement iterators when you don't know how many objects there are (which is pretty much every time) Basically the hasNext() method will look up the next object and cache it. The cached object is then set to null in next(). So you only have to implement one method, fetchNextOrNull which returns null when the iteration has reached the end, and you're done.
  • Constructor Details

    • PrefetchingIterator

      public PrefetchingIterator()
  • Method Details

    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
      Returns:
      true if there is a next item to be returned from the next call to next().
    • peek

      public T peek()
      Returns:
      the next element that will be returned from next() without actually advancing the iterator
    • next

      public T next()
      Uses hasNext() to try to fetch the next item and returns it if found, otherwise it throws a NoSuchElementException.
      Specified by:
      next in interface Iterator<T>
      Returns:
      the next item in the iteration, or throws NoSuchElementException if there's no more items to return.
    • fetchNextOrNull

      protected abstract T fetchNextOrNull()
    • remove

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