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 Iterators that come from
Relations, so that iterators can clean up any resources they are derived from.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TupleIteratorAn always emptyTupleIterator, a bit likeCollections.emptyIterator() -
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()default <A,R> R Collect all values from this tuple iterator in to the givenCollector, and ensures the iterator is closed.default voidforEachRemaining(Consumer<? super Tuple> action) Pass each tuple to the given consumer, closing the iterator once complete (or if in exception is thrown)static TupleIteratorstatic TupleIteratorWraps a normal iterator with this interface, making the close a noop.static <T> TupleIteratorwrappedAndMapped(@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:
closein 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:
forEachRemainingin interfaceIterator<Tuple>
-
singleton
- Returns:
- a
TupleIteratorthat yields a single, fixed result.
-