Package at.jku.ssw.fp.sect04_6
Class Lazy.LazyIterator<T>
- java.lang.Object
-
- at.jku.ssw.fp.sect04_6.Lazy.LazyIterator<T>
-
-
Field Summary
Fields Modifier and Type Field Description private Optional<T>
optNext
An optional with the next value; empty if no value exists; null if a next value has to be generatedprivate Supplier<Optional<T>>
supplier
The supplier function; supplies an optional value with an empty optional if no more values exist.
-
Constructor Summary
Constructors Modifier Constructor Description private
LazyIterator(Supplier<Optional<T>> supplier)
Private constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
Tests if a next value exists.T
next()
Returns the next value, if exists.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Method Detail
-
hasNext
public boolean hasNext()
Tests if a next value exists. A next value exists if the optional valueoptNext
is not empty. Tests theoptNext
value is null and then uses the supplier function to create a new optional value.
-
next
public T next()
Returns the next value, if exists. Throws aNoSuchElementException
if no more element exists.
-
-