PrefetchingIterator (Neo4j Community 2.1.0-M01 API)
Date: 2014-02-20

org.neo4j.helpers.collection

## Class PrefetchingIterator<T>

- java.lang.Object
- - org.neo4j.helpers.collection.PrefetchingIterator<T>

- All Implemented Interfaces:
    Iterator<T>
  Direct Known Subclasses:
    CatchingIteratorWrapper, CombiningIterator, FilteringIterator, LimitingIterator, LinesOfFileIterator, NestingIterator, PrefetchingResourceIterator, RangeIterator

      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 Summary

    Constructors
    Constructor and Description
    `PrefetchingIterator()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `hasNext()`
    `T` | `next()` Uses `hasNext()` to try to fetch the next item and returns it if found, otherwise it throws a `NoSuchElementException`.
    `T` | `peek()`
    `void` | `remove()`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PrefetchingIterator

          public PrefetchingIterator()

  - ### Method Detail

    - #### 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.

    - #### remove

          public void remove()

      Specified by:
        `remove` in interface `Iterator<T>`

Copyright © 2002–2014 The Neo4j Graph Database Project. All rights reserved.