Package org.apache.sis.internal.stream
Class StreamWrapper<T>
java.lang.Object
org.apache.sis.internal.stream.BaseStreamWrapper<T,Stream<T>>
org.apache.sis.internal.stream.StreamWrapper<T>
- Type Parameters:
T
- the type of objects contained in the stream, as specified inStream
interface.
- All Implemented Interfaces:
AutoCloseable
,BaseStream<T,
,Stream<T>> Stream<T>
- Direct Known Subclasses:
DeferredStream
,PaginedStream
A stream which delegates all operations to another stream.
This stream gives to subclasses an opportunity to redirect some operations to optimized implementations.
Note:
It is sometimes necessary to defer the creation of the source stream until a terminal operation is invoked.
Such deferred source creation is managed by the DeferredStream
subclass.
- Since:
- 1.1
- Version:
- 1.1
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.stream.Stream
Stream.Builder<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe source of elements, ornull
if thisStreamWrapper
is no longer the active stream.Fields inherited from class org.apache.sis.internal.stream.BaseStreamWrapper
toClose
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
Creates a new wrapper with initially no source.protected
StreamWrapper
(Stream<T> source) Creates a new wrapper for the given stream. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether all elements of this stream match the provided predicate.boolean
Returns whether at least one element of this stream matches the provided predicate.<R> R
collect
(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner) Performs a mutable reduction on the elements of this stream.<R,
A> R Performs a mutable reduction on the elements of this stream.long
count()
Returns the number of elements in this stream.delegate()
Same assource()
but marks this stream is inactive.distinct()
Returns a stream with distinct elements of this stream.Returns a stream with elements of this stream that match the given predicate.findAny()
Returns any element of this stream.Returns the first element of this stream.<R> Stream
<R> Returns a stream with results of applying the given function to the elements of this stream.flatMapToDouble
(Function<? super T, ? extends DoubleStream> mapper) Returns a stream with results of applying the given function to the elements of this stream.flatMapToInt
(Function<? super T, ? extends IntStream> mapper) Returns a stream with results of applying the given function to the elements of this stream.flatMapToLong
(Function<? super T, ? extends LongStream> mapper) Returns a stream with results of applying the given function to the elements of this stream.void
Performs an action for each element of this stream.void
forEachOrdered
(Consumer<? super T> action) Performs an action for each element of this stream in encounter order.iterator()
Returns an iterator for the elements of this stream.limit
(long maxSize) Returns a stream with truncated at the given number of elements.<R> Stream
<R> Returns a stream with results of applying the given function to the elements of this stream.mapToDouble
(ToDoubleFunction<? super T> mapper) Returns a stream with results of applying the given function to the elements of this stream.mapToInt
(ToIntFunction<? super T> mapper) Returns a stream with results of applying the given function to the elements of this stream.mapToLong
(ToLongFunction<? super T> mapper) Returns a stream with results of applying the given function to the elements of this stream.max
(Comparator<? super T> comparator) Returns the maximum element of this stream according to the provided comparator.min
(Comparator<? super T> comparator) Returns the minimum element of this stream according to the provided comparator.boolean
Returns whether none element of this stream match the provided predicate.Returns an equivalent stream with an additional close handler.parallel()
Returns an equivalent stream that is parallel.Returns a stream performing the specified action on each element when consumed.reduce
(BinaryOperator<T> accumulator) Performs a reduction on the elements of this stream.reduce
(T identity, BinaryOperator<T> accumulator) Performs a reduction on the elements of this stream.<U> U
reduce
(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner) Performs a reduction on the elements of this stream.Returns an equivalent stream that is sequential.skip
(long n) Returns a stream discarding the specified number of elements.sorted()
Returns a stream with elements of this stream sorted in natural order.sorted
(Comparator<? super T> comparator) Returns a stream with elements of this stream sorted using the given comparator.source()
Verifies that this stream is still the active one, then returns the source of this stream.Returns a spliterator for the elements of this stream.Object[]
toArray()
Returns all elements in an array.<A> A[]
toArray
(IntFunction<A[]> generator) Returns all elements in an array.Returns an equivalent stream that is unordered.Invoked after an intermediate operation for determining which stream is the active one.Methods inherited from class org.apache.sis.internal.stream.BaseStreamWrapper
close, inactive, isParallel
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.stream.BaseStream
close, isParallel
Methods inherited from interface java.util.stream.Stream
dropWhile, mapMulti, mapMultiToDouble, mapMultiToInt, mapMultiToLong, takeWhile, toList
-
Field Details
-
source
The source of elements, ornull
if thisStreamWrapper
is no longer the active stream. This is initialized at creation time and set tonull
after it has been determined that all subsequent operations shall be done on a new stream instead ofthis
stream.- See Also:
-
-
Constructor Details
-
StreamWrapper
StreamWrapper()Creates a new wrapper with initially no source. Thesource
field should be initialized by subclass constructor. -
StreamWrapper
Creates a new wrapper for the given stream.- Parameters:
source
- the stream to wrap.
-
-
Method Details
-
source
Verifies that this stream is still the active one, then returns the source of this stream.- Specified by:
source
in classBaseStreamWrapper<T,
Stream<T>> - Returns:
- the stream containing actual data.
- Throws:
IllegalStateException
- if this stream is no longer the active stream on which to apply operations.
-
delegate
Same assource()
but marks this stream is inactive. All subsequent operations must be done on the returned stream. This is used by this class formap(…)
andflatMap(…)
operations. May also be used by subclasses when an operation does not allow further optimizations.- Returns:
- the stream containing actual data.
- Throws:
IllegalStateException
- if this stream is no longer the active stream on which to apply operations.
-
update
Invoked after an intermediate operation for determining which stream is the active one. If this stream is still active, then this method returnsthis
. Otherwise the given stream is returned. -
parallel
Returns an equivalent stream that is parallel.- Specified by:
parallel
in interfaceBaseStream<T,
Stream<T>>
-
sequential
Returns an equivalent stream that is sequential.- Specified by:
sequential
in interfaceBaseStream<T,
Stream<T>>
-
unordered
Returns an equivalent stream that is unordered.- Specified by:
unordered
in interfaceBaseStream<T,
Stream<T>>
-
filter
Returns a stream with elements of this stream that match the given predicate. -
map
Returns a stream with results of applying the given function to the elements of this stream. -
mapToInt
Returns a stream with results of applying the given function to the elements of this stream. -
mapToLong
Returns a stream with results of applying the given function to the elements of this stream. -
mapToDouble
Returns a stream with results of applying the given function to the elements of this stream.- Specified by:
mapToDouble
in interfaceStream<T>
-
flatMap
Returns a stream with results of applying the given function to the elements of this stream. -
flatMapToInt
Returns a stream with results of applying the given function to the elements of this stream.- Specified by:
flatMapToInt
in interfaceStream<T>
-
flatMapToLong
Returns a stream with results of applying the given function to the elements of this stream.- Specified by:
flatMapToLong
in interfaceStream<T>
-
flatMapToDouble
Returns a stream with results of applying the given function to the elements of this stream.- Specified by:
flatMapToDouble
in interfaceStream<T>
-
distinct
Returns a stream with distinct elements of this stream. -
sorted
Returns a stream with elements of this stream sorted in natural order. -
sorted
Returns a stream with elements of this stream sorted using the given comparator. -
peek
Returns a stream performing the specified action on each element when consumed. -
limit
Returns a stream with truncated at the given number of elements. -
skip
Returns a stream discarding the specified number of elements. -
forEach
Performs an action for each element of this stream. -
forEachOrdered
Performs an action for each element of this stream in encounter order.- Specified by:
forEachOrdered
in interfaceStream<T>
-
reduce
Performs a reduction on the elements of this stream. -
reduce
Performs a reduction on the elements of this stream. -
reduce
Performs a reduction on the elements of this stream. -
collect
public <R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner) Performs a mutable reduction on the elements of this stream. -
collect
Performs a mutable reduction on the elements of this stream. -
min
Returns the minimum element of this stream according to the provided comparator. -
max
Returns the maximum element of this stream according to the provided comparator. -
count
public long count()Returns the number of elements in this stream. -
anyMatch
Returns whether at least one element of this stream matches the provided predicate. -
allMatch
Returns whether all elements of this stream match the provided predicate. -
noneMatch
Returns whether none element of this stream match the provided predicate. -
findFirst
Returns the first element of this stream. -
findAny
Returns any element of this stream. -
iterator
Returns an iterator for the elements of this stream.- Specified by:
iterator
in interfaceBaseStream<T,
Stream<T>>
-
spliterator
Returns a spliterator for the elements of this stream.- Specified by:
spliterator
in interfaceBaseStream<T,
Stream<T>>
-
toArray
Returns all elements in an array. -
toArray
Returns all elements in an array. -
onClose
Returns an equivalent stream with an additional close handler.- Specified by:
onClose
in interfaceBaseStream<T,
Stream<T>>
-