Package nz.org.riskscape.engine.relation
Interface TupleIterator
- All Superinterfaces:
AutoCloseable
,Iterator<Tuple>
- All Known Implementing Classes:
Singleton
Brings together the AutoCloseable
and Iterator
interface fo Iterator
s that come from
Relation
s, so that iterators can clean up any resources they are derived from.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final TupleIterator
An always emptyTupleIterator
, a bit likeCollections.emptyIterator()
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
close()
default <A,
R> R Collect all values from this tuple iterator in to the givenCollector
, and ensures the iterator is closed.default void
forEachRemaining
(Consumer<? super Tuple> action) Pass each tuple to the given consumer, closing the iterator once complete (or if in exception is thrown)static TupleIterator
static TupleIterator
Wraps a normal iterator with this interface, making the close a noop.static <T> TupleIterator
wrappedAndMapped
(@NonNull Iterator<T> iterator, @NonNull Function<T, Tuple> mapper) Wraps a possibly normal Iterator with this interface, applying the given mapping functions to values yielded from theTuple
-
Field Details
-
EMPTY
An always empty
TupleIterator
, a bit likeCollections.emptyIterator()
-
-
Method Details
-
wrapped
static TupleIterator wrapped(@NonNull @NonNull Iterator<Tuple> iterator, @NonNull @NonNull Optional<Runnable> onClose) Wraps a normal iterator with this interface, making the close a noop. TODO - maybe add an optional callback for closing?
-
wrappedAndMapped
static <T> TupleIterator wrappedAndMapped(@NonNull @NonNull Iterator<T> iterator, @NonNull @NonNull Function<T, Tuple> mapper) Wraps a possibly normal Iterator with this interface, applying the given mapping functions to values yielded from the
Tuple
-
close
default void close()- Specified by:
close
in interfaceAutoCloseable
-
collect
Collect all values from this tuple iterator in to the given
Collector
, and ensures the iterator is closed.- Returns:
- the result of
Collection
-
forEachRemaining
Pass each tuple to the given consumer, closing the iterator once complete (or if in exception is thrown)
- Specified by:
forEachRemaining
in interfaceIterator<Tuple>
-
singleton
- Returns:
- a
TupleIterator
that yields a single, fixed result.
-