T
- the type of items in the iterator.public class CachingIterator<T> extends Object implements ListIterator<T>
Iterator
which lazily fetches and caches items from the
underlying iterator when items are requested. This enables positioning
as well as going backwards through the iteration.Constructor and Description |
---|
CachingIterator(Iterator<T> source)
Creates a new caching iterator using
source as its underlying
Iterator to get items lazily from. |
Modifier and Type | Method and Description |
---|---|
void |
add(T e)
Not supported by this implement.
|
T |
current()
Returns the last item returned by
next() /previous() . |
boolean |
hasNext()
Returns whether a call to
next() will be able to return
an item or not. |
boolean |
hasPrevious()
Returns whether or not a call to
previous() will be able to
return an item or not. |
T |
next()
Returns the next item given the current
position() . |
int |
nextIndex() |
int |
position()
Returns the current position of the iterator, initially 0.
|
int |
position(int newPosition)
Sets the position of the iterator.
|
T |
previous() |
int |
previousIndex() |
void |
remove()
Not supported by this implement.
|
void |
set(T e)
Not supported by this implement.
|
public boolean hasNext()
next()
will be able to return
an item or not. If the current position()
is beyond the size
of the cache (as will be the case if only calls to
hasNext()
/next()
has been made up to this point)
the underlying iterator is asked, else true
since it can be
returned from the cache.hasNext
in interface Iterator<T>
hasNext
in interface ListIterator<T>
position()
.public T next()
position()
.
If the current position()
is beyond the size
of the cache (as will be the case if only calls to
hasNext()
/next()
has been made up to this point) the
underlying iterator is asked for the next item (and cached if there
was one), else the item is returned from the cache.next
in interface Iterator<T>
next
in interface ListIterator<T>
position()
.public int position()
next()
and also the index of the next item returned by
previous()
plus one. An example:
next()
,
position()
will now return 2.previous()
(which will return "second") and position()
will now be 1public int position(int newPosition)
0
means all the way back to
the beginning. It is also possible to set the position to one higher
than the last item, so that the next call to previous()
would
return the last item. Items will be cached along the way if necessary.newPosition
- the position to set for the iterator, must be
non-negative.public boolean hasPrevious()
previous()
will be able to
return an item or not. So it will return true
if
position()
is bigger than 0.
hasPrevious
in interface ListIterator<T>
public T previous()
previous
in interface ListIterator<T>
public T current()
next()
/previous()
.
If no call has been made to next()
or previous()
since
this iterator was created or since a call to position(int)
has
been made a NoSuchElementException
will be thrown.next()
/previous()
.NoSuchElementException
- if no call has been made to next()
or previous()
since this iterator was created or since a call to
position(int)
has been made.public int nextIndex()
nextIndex
in interface ListIterator<T>
public int previousIndex()
previousIndex
in interface ListIterator<T>
public void remove()
public void set(T e)
set
in interface ListIterator<T>
public void add(T e)
add
in interface ListIterator<T>
Copyright © 2002–2014 The Neo4j Graph Database Project. All rights reserved.