Package com.valqueries
Class StreamCloser<T>
java.lang.Object
com.valqueries.StreamCloser<T>
- All Implemented Interfaces:
AutoCloseable
,BaseStream<T,
,Stream<T>> Stream<T>
Stream wrapper that calls close() on terminal operations. Mapping to primitive streams causes the underlying stream
to collect to a list and close, as we need to ensure that the underlying resource is closed.
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.stream.Stream
Stream.Builder<T extends Object>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
void
close()
<R> R
collect
(Supplier<R> supplier, BiConsumer<R, ? super T> biConsumer, BiConsumer<R, R> biConsumer1) <R,
A> R long
count()
distinct()
findAny()
<R> Stream<R>
flatMapToDouble
(Function<? super T, ? extends DoubleStream> function) flatMapToInt
(Function<? super T, ? extends IntStream> function) flatMapToLong
(Function<? super T, ? extends LongStream> function) void
void
forEachOrdered
(Consumer<? super T> consumer) boolean
iterator()
limit
(long l) <R> Stream<R>
<R> Stream<R>
mapMulti
(BiConsumer<? super T, ? super Consumer<R>> mapper) mapMultiToDouble
(BiConsumer<? super T, ? super DoubleConsumer> mapper) mapMultiToInt
(BiConsumer<? super T, ? super IntConsumer> mapper) mapMultiToLong
(BiConsumer<? super T, ? super LongConsumer> mapper) mapToDouble
(ToDoubleFunction<? super T> toDoubleFunction) mapToInt
(ToIntFunction<? super T> toIntFunction) mapToLong
(ToLongFunction<? super T> toLongFunction) max
(Comparator<? super T> comparator) min
(Comparator<? super T> comparator) boolean
Works the same as the baseBaseStream.onClose(Runnable)
but note that the `StreamCloser` may in some circumstances close and create a new backing list for some operations.parallel()
reduce
(BinaryOperator<T> binaryOperator) reduce
(T t, BinaryOperator<T> binaryOperator) <U> U
reduce
(U u, BiFunction<U, ? super T, U> biFunction, BinaryOperator<U> binaryOperator) skip
(long l) sorted()
sorted
(Comparator<? super T> comparator) Object[]
toArray()
<A> A[]
toArray
(IntFunction<A[]> intFunction) toList()
-
Constructor Details
-
StreamCloser
-
-
Method Details
-
filter
-
map
-
mapToInt
-
mapToLong
-
mapToDouble
- Specified by:
mapToDouble
in interfaceStream<T>
-
flatMap
-
flatMapToInt
- Specified by:
flatMapToInt
in interfaceStream<T>
-
flatMapToLong
- Specified by:
flatMapToLong
in interfaceStream<T>
-
flatMapToDouble
- Specified by:
flatMapToDouble
in interfaceStream<T>
-
mapMulti
-
mapMultiToInt
- Specified by:
mapMultiToInt
in interfaceStream<T>
-
mapMultiToLong
- Specified by:
mapMultiToLong
in interfaceStream<T>
-
mapMultiToDouble
- Specified by:
mapMultiToDouble
in interfaceStream<T>
-
distinct
-
sorted
-
sorted
-
peek
-
limit
-
skip
-
takeWhile
-
dropWhile
-
forEach
-
forEachOrdered
- Specified by:
forEachOrdered
in interfaceStream<T>
-
toArray
-
toArray
-
reduce
-
reduce
-
reduce
-
collect
public <R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> biConsumer, BiConsumer<R, R> biConsumer1) -
collect
-
toList
-
min
-
max
-
count
public long count() -
anyMatch
-
allMatch
-
noneMatch
-
findFirst
-
findAny
-
iterator
- Specified by:
iterator
in interfaceBaseStream<T,
Stream<T>>
-
nonClosingIterator
- Returns:
- an iterator that does not close the stream. Make sure this stream is closed after the iterator is used.
-
spliterator
- Specified by:
spliterator
in interfaceBaseStream<T,
Stream<T>>
-
isParallel
public boolean isParallel()- Specified by:
isParallel
in interfaceBaseStream<T,
Stream<T>>
-
sequential
- Specified by:
sequential
in interfaceBaseStream<T,
Stream<T>>
-
parallel
- Specified by:
parallel
in interfaceBaseStream<T,
Stream<T>>
-
unordered
- Specified by:
unordered
in interfaceBaseStream<T,
Stream<T>>
-
onClose
Works the same as the baseBaseStream.onClose(Runnable)
but note that the `StreamCloser` may in some circumstances close and create a new backing list for some operations. As such any runnable bound in this way is only guaranteed to be run after any operations which were specified before it was bound.E.g. the following code may produce different execution timings for `x`, depending on the underlying stream source:
compared tostream.onClose(x).mapToInt(mapper);
stream.mapToInt(mapper).onClose(x);
- Specified by:
onClose
in interfaceBaseStream<T,
Stream<T>> - Parameters:
runnable
- A task to execute when the stream is closed- Returns:
- a stream with a handler that is run if the stream is closed
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceBaseStream<T,
Stream<T>>
-