java.lang.Object
org.apache.jena.util.iterator.NiceIterator<T>
org.apache.jena.util.iterator.LazyIterator<T>
- All Implemented Interfaces:
Iterator<T>
,org.apache.jena.atlas.iterator.IteratorCloseable<T>
,org.apache.jena.atlas.lib.Closeable
,ClosableIterator<T>
,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 iterate (i.e. use one of the hasNext
, next
,
remove
, removeNext
operations,
maybe indirectly via toList
).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
default close: don't need to do anything.abstract ExtendedIterator<T>
create()
The subclass must define this to return the ExtendedIterator to invoke.void
forEachRemaining
(Consumer<? super T> action) boolean
hasNext()
default hasNext: no elements, return false.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
-
Constructor Details
-
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 Details
-
hasNext
public boolean hasNext()Description copied from class:NiceIterator
default hasNext: no elements, return false. -
next
Description copied from class:NiceIterator
default next: throw an exception. -
forEachRemaining
-
remove
public void remove()Description copied from class:NiceIterator
default remove: we have no elements, so we can't remove any. -
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 interfaceorg.apache.jena.atlas.lib.Closeable
- Overrides:
close
in classNiceIterator<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.
-