Package apoc.util.collection
Class PrefetchingIterator<T>
java.lang.Object
apoc.util.collection.PrefetchingIterator<T>
- All Implemented Interfaces:
Iterator<T>
- Direct Known Subclasses:
FilteringIterator,PrefetchingResourceIterator
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() -
peek
- Returns:
- the next element that will be returned from
next()without actually advancing the iterator
-
next
UseshasNext()to try to fetch the next item and returns it if found, otherwise it throws aNoSuchElementException.- Specified by:
nextin interfaceIterator<T>- Returns:
- the next item in the iteration, or throws
NoSuchElementExceptionif there's no more items to return.
-
fetchNextOrNull
-
remove
public void remove()
-