Neo4j Community

org.neo4j.helpers.collection
Class PagingIterator<T>

java.lang.Object
  extended by org.neo4j.helpers.collection.CachingIterator<T>
      extended by org.neo4j.helpers.collection.PagingIterator<T>
Type Parameters:
T - the type of items in this iterator.
All Implemented Interfaces:
Iterator<T>, ListIterator<T>

public class PagingIterator<T>
extends CachingIterator<T>

A CachingIterator which can more easily divide the items into pages, where optionally each page can be seen as its own Iterator instance for convenience using nextPage().

Author:
Mattias Persson

Constructor Summary
PagingIterator(Iterator<T> source, int pageSize)
          Creates a new paging iterator with source as its underlying Iterator to lazily get items from.
 
Method Summary
 Iterator<T> nextPage()
          Returns a new Iterator instance which exposes the current page as its own iterator, which fetches items lazily from the underlying iterator.
 int page()
           
 int page(int newPage)
          Sets the current page of the iterator.
 
Methods inherited from class org.neo4j.helpers.collection.CachingIterator
add, current, hasNext, hasPrevious, next, nextIndex, position, position, previous, previousIndex, remove, set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PagingIterator

public PagingIterator(Iterator<T> source,
                      int pageSize)
Creates a new paging iterator with source as its underlying Iterator to lazily get items from.

Parameters:
source - the underlying Iterator to lazily get items from.
pageSize - the max number of items in each page.
Method Detail

page

public int page()
Returns:
the page the iterator is currently at, starting a 0. This value is based on the CachingIterator.position() and the page size.

page

public int page(int newPage)
Sets the current page of the iterator. 0 means the first page.

Parameters:
newPage - the current page to set for the iterator, must be non-negative. The next item returned by the iterator will be the first item in that page.
Returns:
the page before changing to the new page.

nextPage

public Iterator<T> nextPage()
Returns a new Iterator instance which exposes the current page as its own iterator, which fetches items lazily from the underlying iterator. It is discouraged to use an Iterator returned from this method at the same time as using methods like CachingIterator.next() or CachingIterator.previous(), where the results may be unpredictable. So either use only nextPage() (in conjunction with page(int) if necessary) or go with regular CachingIterator.next()/CachingIterator.previous().

Returns:
the next page as an Iterator.

Neo4j Community

Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.