com.hp.hpl.jena.util.iterator
Class LazyIterator<T>

java.lang.Object
  extended by com.hp.hpl.jena.util.iterator.LazyIterator<T>
All Implemented Interfaces:
ClosableIterator<T>, ExtendedIterator<T>, java.util.Iterator<T>

public abstract class LazyIterator<T>
extends java.lang.Object
implements ExtendedIterator<T>

An ExtendedIterator that is created lazily. This is useful when constructing an iterator is expensive and you'd prefer to delay doing it until certain it's actually needed. For example, if you have iterator1.andThen(iterator2) you could implement iterator2 as a LazyIterator. The sequence to be defined is defined by the subclass's definition of create(). That is called exactly once on the first attempt to interact with the LazyIterator.

Version:
$Revision: 1.1 $
Author:
jjc, modified to use ExtendedIterators by csayers

Constructor Summary
LazyIterator()
          An ExtendedIterator that is created lazily.
 
Method Summary
 ExtendedIterator<T> andThen(ClosableIterator<? extends T> other)
           
 void close()
          Close the iterator.
abstract  ExtendedIterator<T> create()
          The subclass must define this to return the ExtendedIterator to invoke.
 ExtendedIterator<T> filterDrop(Filter<T> f)
          return a new iterator containing only the elements of _this_ which are rejected by the filter _f_.
 ExtendedIterator<T> filterKeep(Filter<T> f)
          return a new iterator containing only the elements of _this_ which pass the filter _f_.
 boolean hasNext()
           
<U> ExtendedIterator<U>
mapWith(Map1<T,U> map1)
          return a new iterator where each element is the result of applying _map1_ to the corresponding element of _this_.
 T next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.hp.hpl.jena.util.iterator.ExtendedIterator
andThen, removeNext, toList, toSet
 

Constructor Detail

LazyIterator

public LazyIterator()
An ExtendedIterator that is created lazily. This constructor has very low overhead - the real work is delayed until the first attempt to use the iterator.

Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<T>

next

public T next()
Specified by:
next in interface java.util.Iterator<T>

remove

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

andThen

public ExtendedIterator<T> andThen(ClosableIterator<? extends T> other)

filterKeep

public ExtendedIterator<T> filterKeep(Filter<T> f)
Description copied from interface: ExtendedIterator
return a new iterator containing only the elements of _this_ which pass the filter _f_. The order of the elements is preserved. Does not copy _this_, which is consumed as the result is consumed.

Specified by:
filterKeep in interface ExtendedIterator<T>

filterDrop

public ExtendedIterator<T> filterDrop(Filter<T> f)
Description copied from interface: ExtendedIterator
return a new iterator containing only the elements of _this_ which are rejected by the filter _f_. The order of the elements is preserved. Does not copy _this_, which is consumed as the result is consumed.

Specified by:
filterDrop in interface ExtendedIterator<T>

mapWith

public <U> ExtendedIterator<U> mapWith(Map1<T,U> map1)
Description copied from interface: ExtendedIterator
return a new iterator where each element is the result of applying _map1_ to the corresponding element of _this_. _this_ is not copied; it is consumed as the result is consumed.

Specified by:
mapWith in interface ExtendedIterator<T>

close

public void close()
Description copied from interface: ClosableIterator
Close the iterator. Other operations on this iterator may now throw an exception. A ClosableIterator may be closed as many times as desired - the subsequent calls do nothing.

Specified by:
close in interface ClosableIterator<T>

create

public abstract ExtendedIterator<T> create()
The subclass must define this to return the ExtendedIterator to invoke. This method will be called at most once, on the first attempt to use the iterator. From then on, all calls to this will be passed through to the returned Iterator.

Returns:
The parent iterator defining the sequence.


Copyright ? 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP