Package org.apache.jena.util.iterator
Class LazyIterator<T>
- java.lang.Object
-
- org.apache.jena.util.iterator.NiceIterator<T>
-
- org.apache.jena.util.iterator.LazyIterator<T>
-
- All Implemented Interfaces:
java.util.Iterator<T>
,IteratorCloseable<T>
,Closeable
,ClosableIterator<T>
,ExtendedIterator<T>
public abstract class LazyIterator<T> extends NiceIterator<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 haveiterator1.andThen(iterator2)
you could implement iterator2 as a LazyIterator. The sequence to be defined is defined by the subclass's definition ofcreate()
. That is called exactly once on the first attempt to iterate (i.e. use one of thehasNext
,next
,remove
,removeNext
operations, maybe indirectly viatoList
).
-
-
Constructor Summary
Constructors Constructor Description LazyIterator()
An ExtendedIterator that is created lazily.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
default close: don't need to do anything.abstract ExtendedIterator<T>
create()
The subclass must define this to return the ExtendedIterator to invoke.boolean
hasNext()
default hasNext: no elements, return false.T
next()
default next: throw an exception.void
remove()
default remove: we have no elements, so we can't remove any.-
Methods inherited from class org.apache.jena.util.iterator.NiceIterator
andThen, andThen, asList, asSet, close, emptyIterator, filterDrop, filterKeep, mapWith, removeNext, toList, toSet
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.jena.util.iterator.ExtendedIterator
forEach, nextOptional
-
-
-
-
Method Detail
-
hasNext
public boolean hasNext()
Description copied from class:NiceIterator
default hasNext: no elements, return false.- Specified by:
hasNext
in interfacejava.util.Iterator<T>
- Overrides:
hasNext
in classNiceIterator<T>
-
next
public T next()
Description copied from class:NiceIterator
default next: throw an exception.- Specified by:
next
in interfacejava.util.Iterator<T>
- Overrides:
next
in classNiceIterator<T>
-
remove
public void remove()
Description copied from class:NiceIterator
default remove: we have no elements, so we can't remove any.- Specified by:
remove
in interfacejava.util.Iterator<T>
- Overrides:
remove
in classNiceIterator<T>
-
close
public void close()
Description copied from class:NiceIterator
default close: don't need to do anything.- Specified by:
close
in interfaceClosableIterator<T>
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classNiceIterator<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.
-
-