Package nl.vpro.util
Class LazyIterator<T>
java.lang.Object
nl.vpro.util.LazyIterator<T>
- All Implemented Interfaces:
AutoCloseable
,Iterator<T>
,CloseableIterator<T>
,Counted
,CountedIterator<T>
Wraps a supplier around an iterator. This way you can delay the instantiation of the actual iterator until the first call
of hasNext() or next().
- Author:
- Michiel Meeuwissen
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface nl.vpro.util.CloseableIterator
CloseableIterator.WrappedCloseableIterator<S>, CloseableIterator.WrappedPeekingCloseableIterator<S>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> LazyIterator.Builder<T>
builder()
void
close()
getCount()
The current position.getSize()
The size, if known, of the collection this iterator is representingboolean
hasNext()
next()
static <S> LazyIterator<S>
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface nl.vpro.util.CountedIterator
getTotalSize, peeking, spliterator, stream
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
LazyIterator
-
-
Method Details
-
of
-
hasNext
public boolean hasNext() -
next
-
getSize
Description copied from interface:CountedIterator
The size, if known, of the collection this iterator is representing- Specified by:
getSize
in interfaceCountedIterator<T>
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCountedIterator<T>
- Throws:
Exception
-
builder
-
getCount
Description copied from interface:CountedIterator
The current position. Will return1
after first successfull call toIterator.next()
,2
after the second one, and so on. It will return0
before the first call.- Specified by:
getCount
in interfaceCounted
- Specified by:
getCount
in interfaceCountedIterator<T>
-