Class BaseStreamEx<T,S extends java.util.stream.BaseStream<T,S>,SPLTR extends java.util.Spliterator<T>,B extends BaseStreamEx<T,S,SPLTR,B>>
- java.lang.Object
-
- one.util.streamex.BaseStreamEx<T,S,SPLTR,B>
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.util.stream.BaseStream<T,S>
- Direct Known Subclasses:
AbstractStreamEx
,DoubleStreamEx
,IntStreamEx
,LongStreamEx
abstract class BaseStreamEx<T,S extends java.util.stream.BaseStream<T,S>,SPLTR extends java.util.Spliterator<T>,B extends BaseStreamEx<T,S,SPLTR,B>> extends java.lang.Object implements java.util.stream.BaseStream<T,S>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
CONSUMED_MESSAGE
(package private) StreamContext
context
(package private) SPLTR
spliterator
private S
stream
-
Constructor Summary
Constructors Constructor Description BaseStreamEx(SPLTR spliterator, StreamContext context)
BaseStreamEx(S stream, StreamContext context)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract <U> U
chain(java.util.function.Function<? super B,U> mapper)
Applies the supplied function to this stream and returns the result of the function.void
close()
(package private) abstract S
createStream()
boolean
isParallel()
S
onClose(java.lang.Runnable closeHandler)
S
parallel()
S
parallel(java.util.concurrent.ForkJoinPool fjp)
Returns an equivalent stream that is parallel and bound to the suppliedForkJoinPool
.S
sequential()
SPLTR
spliterator()
(package private) S
stream()
S
unordered()
-
-
-
Field Detail
-
CONSUMED_MESSAGE
static final java.lang.String CONSUMED_MESSAGE
- See Also:
- Constant Field Values
-
context
StreamContext context
-
-
Constructor Detail
-
BaseStreamEx
BaseStreamEx(S stream, StreamContext context)
-
BaseStreamEx
BaseStreamEx(SPLTR spliterator, StreamContext context)
-
-
Method Detail
-
createStream
abstract S createStream()
-
stream
final S stream()
-
spliterator
public SPLTR spliterator()
-
isParallel
public boolean isParallel()
-
sequential
public S sequential()
-
parallel
public S parallel()
If this stream was created using
parallel(ForkJoinPool)
, the new stream forgets about supplied customForkJoinPool
and its terminal operation will be executed in common pool.
-
parallel
public S parallel(java.util.concurrent.ForkJoinPool fjp)
Returns an equivalent stream that is parallel and bound to the suppliedForkJoinPool
.This is an intermediate operation.
The terminal operation of this stream or any derived stream (except the streams created via
parallel()
orsequential()
methods) will be executed inside the suppliedForkJoinPool
. If current thread does not belong to that pool, it will wait till calculation finishes.- Parameters:
fjp
- aForkJoinPool
to submit the stream operation to.- Returns:
- a parallel stream bound to the supplied
ForkJoinPool
- Since:
- 0.2.0
-
unordered
public S unordered()
-
onClose
public S onClose(java.lang.Runnable closeHandler)
-
close
public void close()
-
chain
public abstract <U> U chain(java.util.function.Function<? super B,U> mapper)
Applies the supplied function to this stream and returns the result of the function.This method can be used to add more functionality in the fluent style. For example, consider user-defined static method
batches(stream, n)
which breaks the stream into batches of given length. Normally you would writebatches(StreamEx.of(input).map(...), 10).filter(...)
. Using thechain()
method you can write in more fluent manner:StreamEx.of(input).map(...).chain(s -> batches(s, 10)).filter(...)
.You could even go further and define a method which returns a function like
<T> UnaryOperator<StreamEx<T>> batches(int n)
and use it like this:StreamEx.of(input).map(...).chain(batches(10)).filter(...)
.- Type Parameters:
U
- the type of the function result.- Parameters:
mapper
- function to invoke.- Returns:
- the result of the function invocation.
- Since:
- 0.5.4
-
-