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 TypeMethodDescriptionbooleanbooleanvoidclose()<R> Rcollect(Supplier<R> supplier, BiConsumer<R, ? super T> biConsumer, BiConsumer<R, R> biConsumer1) <R,A> R longcount()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) voidvoidforEachOrdered(Consumer<? super T> consumer) booleaniterator()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) booleanWorks 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> Ureduce(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:
mapToDoublein interfaceStream<T>
-
flatMap
-
flatMapToInt
- Specified by:
flatMapToIntin interfaceStream<T>
-
flatMapToLong
- Specified by:
flatMapToLongin interfaceStream<T>
-
flatMapToDouble
- Specified by:
flatMapToDoublein interfaceStream<T>
-
mapMulti
-
mapMultiToInt
- Specified by:
mapMultiToIntin interfaceStream<T>
-
mapMultiToLong
- Specified by:
mapMultiToLongin interfaceStream<T>
-
mapMultiToDouble
- Specified by:
mapMultiToDoublein interfaceStream<T>
-
distinct
-
sorted
-
sorted
-
peek
-
limit
-
skip
-
takeWhile
-
dropWhile
-
forEach
-
forEachOrdered
- Specified by:
forEachOrderedin 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:
iteratorin 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:
spliteratorin interfaceBaseStream<T,Stream<T>>
-
isParallel
public boolean isParallel()- Specified by:
isParallelin interfaceBaseStream<T,Stream<T>>
-
sequential
- Specified by:
sequentialin interfaceBaseStream<T,Stream<T>>
-
parallel
- Specified by:
parallelin interfaceBaseStream<T,Stream<T>>
-
unordered
- Specified by:
unorderedin 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:
onClosein 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceBaseStream<T,Stream<T>>
-