E_IN
- type of elements in the upstream sourcepublic abstract class LongPipeline<E_IN> extends AbstractPipeline<E_IN,Long,LongStream> implements LongStream
long
.Modifier and Type | Class and Description |
---|---|
static class |
LongPipeline.Head<E_IN>
Source stage of a LongPipeline.
|
static class |
LongPipeline.StatefulOp<E_IN>
Base class for a stateful intermediate stage of a LongStream.
|
static class |
LongPipeline.StatelessOp<E_IN>
Base class for a stateless intermediate stage of a LongStream.
|
LongStream.Builder
sourceOrOpFlags
Modifier and Type | Method and Description |
---|---|
boolean |
allMatch(LongPredicate predicate)
Returns whether all elements of this stream match the provided predicate.
|
boolean |
anyMatch(LongPredicate predicate)
Returns whether any elements of this stream match the provided
predicate.
|
DoubleStream |
asDoubleStream()
Returns a
DoubleStream consisting of the elements of this stream,
converted to double . |
OptionalDouble |
average()
Returns an
OptionalDouble describing the arithmetic mean of elements of
this stream, or an empty optional if this stream is empty. |
Stream<Long> |
boxed()
Returns a
Stream consisting of the elements of this stream,
each boxed to a Long . |
<R> R |
collect(Supplier<R> supplier,
ObjLongConsumer<R> accumulator,
BiConsumer<R,R> combiner)
Performs a mutable
reduction operation on the elements of this stream.
|
long |
count()
Returns the count of elements in this stream.
|
LongStream |
distinct()
Returns a stream consisting of the distinct elements of this stream.
|
<P_IN> Node<Long> |
evaluateToNode(PipelineHelper<Long> helper,
Spliterator<P_IN> spliterator,
boolean flattenTree,
IntFunction<Long[]> generator)
Collect elements output from a pipeline into a Node that holds elements
of this shape.
|
LongStream |
filter(LongPredicate predicate)
Returns a stream consisting of the elements of this stream that match
the given predicate.
|
OptionalLong |
findAny()
Returns an
OptionalLong describing some element of the stream, or
an empty OptionalLong if the stream is empty. |
OptionalLong |
findFirst()
Returns an
OptionalLong describing the first element of this
stream, or an empty OptionalLong if the stream is empty. |
LongStream |
flatMap(LongFunction<? extends LongStream> mapper)
Returns a stream consisting of the results of replacing each element of
this stream with the contents of a mapped stream produced by applying
the provided mapping function to each element.
|
void |
forEach(LongConsumer action)
Performs an action for each element of this stream.
|
void |
forEachOrdered(LongConsumer action)
Performs an action for each element of this stream, guaranteeing that
each element is processed in encounter order for streams that have a
defined encounter order.
|
void |
forEachWithCancel(Spliterator<Long> spliterator,
Sink<Long> sink)
Traverse the elements of a spliterator compatible with this stream shape,
pushing those elements into a sink.
|
StreamShape |
getOutputShape()
Get the output shape of the pipeline.
|
PrimitiveIterator.OfLong |
iterator()
Returns an iterator for the elements of this stream.
|
Spliterator.OfLong |
lazySpliterator(Supplier<? extends Spliterator<Long>> supplier)
Create a lazy spliterator that wraps and obtains the supplied the
spliterator when a method is invoked on the lazy spliterator.
|
LongStream |
limit(long maxSize)
Returns a stream consisting of the elements of this stream, truncated
to be no longer than
maxSize in length. |
Node.Builder<Long> |
makeNodeBuilder(long exactSizeIfKnown,
IntFunction<Long[]> generator)
Make a node builder compatible with this stream shape.
|
LongStream |
map(LongUnaryOperator mapper)
Returns a stream consisting of the results of applying the given
function to the elements of this stream.
|
DoubleStream |
mapToDouble(LongToDoubleFunction mapper)
Returns a
DoubleStream consisting of the results of applying the
given function to the elements of this stream. |
IntStream |
mapToInt(LongToIntFunction mapper)
Returns an
IntStream consisting of the results of applying the
given function to the elements of this stream. |
<U> Stream<U> |
mapToObj(LongFunction<? extends U> mapper)
Returns an object-valued
Stream consisting of the results of
applying the given function to the elements of this stream. |
OptionalLong |
max()
Returns an
OptionalLong describing the maximum element of this
stream, or an empty optional if this stream is empty. |
OptionalLong |
min()
Returns an
OptionalLong describing the minimum element of this
stream, or an empty optional if this stream is empty. |
boolean |
noneMatch(LongPredicate predicate)
Returns whether no elements of this stream match the provided predicate.
|
LongStream |
peek(LongConsumer action)
Returns a stream consisting of the elements of this stream, additionally
performing the provided action on each element as elements are consumed
from the resulting stream.
|
OptionalLong |
reduce(LongBinaryOperator op)
Performs a reduction on the
elements of this stream, using an
associative accumulation
function, and returns an
OptionalLong describing the reduced value,
if any. |
long |
reduce(long identity,
LongBinaryOperator op)
Performs a reduction on the
elements of this stream, using the provided identity value and an
associative
accumulation function, and returns the reduced value.
|
LongStream |
skip(long n)
Returns a stream consisting of the remaining elements of this stream
after discarding the first
n elements of the stream. |
LongStream |
sorted()
Returns a stream consisting of the elements of this stream in sorted
order.
|
Spliterator.OfLong |
spliterator()
Returns a spliterator for the elements of this stream.
|
long |
sum()
Returns the sum of elements in this stream.
|
LongSummaryStatistics |
summaryStatistics()
Returns a
LongSummaryStatistics describing various summary data
about the elements of this stream. |
long[] |
toArray()
Returns an array containing the elements of this stream.
|
LongStream |
unordered()
Returns an equivalent stream that is
unordered.
|
<P_IN> Spliterator<Long> |
wrap(PipelineHelper<Long> ph,
Supplier<Spliterator<P_IN>> supplier,
boolean isParallel)
Create a spliterator that wraps a source spliterator, compatible with
this stream shape, and operations associated with a
PipelineHelper . |
close, evaluate, evaluateToArrayNode, getStreamAndOpFlags, getStreamFlags, isParallel, onClose, opEvaluateParallel, opEvaluateParallelLazy, opIsStateful, opWrapSink, parallel, sequential, wrapSink
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
builder, concat, empty, generate, iterate, of, of, parallel, range, rangeClosed, sequential
close, isParallel, onClose
public final StreamShape getOutputShape()
AbstractPipeline
getOutputShape
in class AbstractPipeline<E_IN,Long,LongStream>
public final <P_IN> Node<Long> evaluateToNode(PipelineHelper<Long> helper, Spliterator<P_IN> spliterator, boolean flattenTree, IntFunction<Long[]> generator)
AbstractPipeline
evaluateToNode
in class AbstractPipeline<E_IN,Long,LongStream>
helper
- the pipeline helper describing the pipeline stagesspliterator
- the source spliteratorflattenTree
- true if the returned node should be flattenedgenerator
- the array generatorpublic final <P_IN> Spliterator<Long> wrap(PipelineHelper<Long> ph, Supplier<Spliterator<P_IN>> supplier, boolean isParallel)
AbstractPipeline
PipelineHelper
.wrap
in class AbstractPipeline<E_IN,Long,LongStream>
ph
- the pipeline helper describing the pipeline stagessupplier
- the supplier of a spliteratorpublic final Spliterator.OfLong lazySpliterator(Supplier<? extends Spliterator<Long>> supplier)
AbstractPipeline
lazySpliterator
in class AbstractPipeline<E_IN,Long,LongStream>
supplier
- the supplier of a spliteratorpublic final void forEachWithCancel(Spliterator<Long> spliterator, Sink<Long> sink)
AbstractPipeline
forEachWithCancel
in class AbstractPipeline<E_IN,Long,LongStream>
spliterator
- the spliterator to pull elements fromsink
- the sink to push elements topublic final Node.Builder<Long> makeNodeBuilder(long exactSizeIfKnown, IntFunction<Long[]> generator)
AbstractPipeline
makeNodeBuilder
in class AbstractPipeline<E_IN,Long,LongStream>
exactSizeIfKnown
- if >=0, then a node builder will be
created that has a fixed capacity of at most sizeIfKnown elements. If
< 0, then the node builder has an unfixed capacity. A fixed
capacity node builder will throw exceptions if an element is added after
builder has reached capacity, or is built before the builder has reached
capacity.generator
- the array generator to be used to create instances of a
T[] array. For implementations supporting primitive nodes, this parameter
may be ignored.public final PrimitiveIterator.OfLong iterator()
BaseStream
This is a terminal operation.
iterator
in interface BaseStream<Long,LongStream>
iterator
in interface LongStream
public final Spliterator.OfLong spliterator()
BaseStream
This is a terminal operation.
spliterator
in interface BaseStream<Long,LongStream>
spliterator
in interface LongStream
spliterator
in class AbstractPipeline<E_IN,Long,LongStream>
public final DoubleStream asDoubleStream()
LongStream
DoubleStream
consisting of the elements of this stream,
converted to double
.
This is an intermediate operation.
asDoubleStream
in interface LongStream
DoubleStream
consisting of the elements of this stream,
converted to double
public final Stream<Long> boxed()
LongStream
Stream
consisting of the elements of this stream,
each boxed to a Long
.
This is an intermediate operation.
boxed
in interface LongStream
Stream
consistent of the elements of this stream,
each boxed to Long
public final LongStream map(LongUnaryOperator mapper)
LongStream
This is an intermediate operation.
map
in interface LongStream
mapper
- a non-interfering,
stateless
function to apply to each elementpublic final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper)
LongStream
Stream
consisting of the results of
applying the given function to the elements of this stream.
This is an intermediate operation.
mapToObj
in interface LongStream
U
- the element type of the new streammapper
- a non-interfering,
stateless
function to apply to each elementpublic final IntStream mapToInt(LongToIntFunction mapper)
LongStream
IntStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToInt
in interface LongStream
mapper
- a non-interfering,
stateless
function to apply to each elementpublic final DoubleStream mapToDouble(LongToDoubleFunction mapper)
LongStream
DoubleStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToDouble
in interface LongStream
mapper
- a non-interfering,
stateless
function to apply to each elementpublic final LongStream flatMap(LongFunction<? extends LongStream> mapper)
LongStream
closed
after its contents
have been placed into this stream. (If a mapped stream is null
an empty stream is used, instead.)
This is an intermediate operation.
flatMap
in interface LongStream
mapper
- a non-interfering,
stateless
function to apply to each element which produces a
LongStream
of new valuesStream.flatMap(Function)
public LongStream unordered()
BaseStream
This is an intermediate operation.
unordered
in interface BaseStream<Long,LongStream>
public final LongStream filter(LongPredicate predicate)
LongStream
This is an intermediate operation.
filter
in interface LongStream
predicate
- a non-interfering,
stateless
predicate to apply to each element to determine if it
should be includedpublic final LongStream peek(LongConsumer action)
LongStream
This is an intermediate operation.
For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.
peek
in interface LongStream
action
- a
non-interfering action to perform on the elements as
they are consumed from the streampublic final LongStream limit(long maxSize)
LongStream
maxSize
in length.
limit
in interface LongStream
maxSize
- the number of elements the stream should be limited topublic final LongStream skip(long n)
LongStream
n
elements of the stream.
If this stream contains fewer than n
elements then an
empty stream will be returned.
This is a stateful intermediate operation.
skip
in interface LongStream
n
- the number of leading elements to skippublic final LongStream sorted()
LongStream
This is a stateful intermediate operation.
sorted
in interface LongStream
public final LongStream distinct()
LongStream
This is a stateful intermediate operation.
distinct
in interface LongStream
public void forEach(LongConsumer action)
LongStream
This is a terminal operation.
For parallel stream pipelines, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever thread the library chooses. If the action accesses shared state, it is responsible for providing the required synchronization.
forEach
in interface LongStream
action
- a
non-interfering action to perform on the elementspublic void forEachOrdered(LongConsumer action)
LongStream
This is a terminal operation.
forEachOrdered
in interface LongStream
action
- a
non-interfering action to perform on the elementsLongStream.forEach(LongConsumer)
public final long sum()
LongStream
return reduce(0, Long::sum);
This is a terminal operation.
sum
in interface LongStream
public final OptionalLong min()
LongStream
OptionalLong
describing the minimum element of this
stream, or an empty optional if this stream is empty. This is a special
case of a reduction
and is equivalent to:
return reduce(Long::min);
This is a terminal operation.
min
in interface LongStream
OptionalLong
containing the minimum element of this
stream, or an empty OptionalLong
if the stream is emptypublic final OptionalLong max()
LongStream
OptionalLong
describing the maximum element of this
stream, or an empty optional if this stream is empty. This is a special
case of a reduction
and is equivalent to:
return reduce(Long::max);
This is a terminal operation.
max
in interface LongStream
OptionalLong
containing the maximum element of this
stream, or an empty OptionalLong
if the stream is emptypublic final OptionalDouble average()
LongStream
OptionalDouble
describing the arithmetic mean of elements of
this stream, or an empty optional if this stream is empty. This is a
special case of a
reduction.
This is a terminal operation.
average
in interface LongStream
OptionalDouble
containing the average element of this
stream, or an empty optional if the stream is emptypublic final long count()
LongStream
return map(e -> 1L).sum();
This is a terminal operation.
count
in interface LongStream
public final LongSummaryStatistics summaryStatistics()
LongStream
LongSummaryStatistics
describing various summary data
about the elements of this stream. This is a special case of a
reduction.
This is a terminal operation.
summaryStatistics
in interface LongStream
LongSummaryStatistics
describing various summary data
about the elements of this streampublic final long reduce(long identity, LongBinaryOperator op)
LongStream
long result = identity;
for (long element : this stream)
result = accumulator.applyAsLong(result, element)
return result;
but is not constrained to execute sequentially.
The identity
value must be an identity for the accumulator
function. This means that for all x
,
accumulator.apply(identity, x)
is equal to x
.
The accumulator
function must be an
associative function.
This is a terminal operation.
reduce
in interface LongStream
identity
- the identity value for the accumulating functionop
- an associative,
non-interfering,
stateless
function for combining two valuesLongStream.sum()
,
LongStream.min()
,
LongStream.max()
,
LongStream.average()
public final OptionalLong reduce(LongBinaryOperator op)
LongStream
OptionalLong
describing the reduced value,
if any. This is equivalent to:
boolean foundAny = false;
long result = null;
for (long element : this stream) {
if (!foundAny) {
foundAny = true;
result = element;
}
else
result = accumulator.applyAsLong(result, element);
}
return foundAny ? OptionalLong.of(result) : OptionalLong.empty();
but is not constrained to execute sequentially.
The accumulator
function must be an
associative function.
This is a terminal operation.
reduce
in interface LongStream
op
- an associative,
non-interfering,
stateless
function for combining two valuesLongStream.reduce(long, LongBinaryOperator)
public final <R> R collect(Supplier<R> supplier, ObjLongConsumer<R> accumulator, BiConsumer<R,R> combiner)
LongStream
ArrayList
, and elements are incorporated by updating
the state of the result rather than by replacing the result. This
produces a result equivalent to:
R result = supplier.get();
for (long element : this stream)
accumulator.accept(result, element);
return result;
Like LongStream.reduce(long, LongBinaryOperator)
, collect
operations
can be parallelized without requiring additional synchronization.
This is a terminal operation.
collect
in interface LongStream
R
- type of the resultsupplier
- a function that creates a new result container. For a
parallel execution, this function may be called
multiple times and must return a fresh value each time.accumulator
- an associative,
non-interfering,
stateless
function for incorporating an additional element into a resultcombiner
- an associative,
non-interfering,
stateless
function for combining two values, which must be
compatible with the accumulator functionStream.collect(Supplier, BiConsumer, BiConsumer)
public final boolean anyMatch(LongPredicate predicate)
LongStream
false
is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
anyMatch
in interface LongStream
predicate
- a non-interfering,
stateless
predicate to apply to elements of this streamtrue
if any elements of the stream match the provided
predicate, otherwise false
public final boolean allMatch(LongPredicate predicate)
LongStream
true
is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
allMatch
in interface LongStream
predicate
- a non-interfering,
stateless
predicate to apply to elements of this streamtrue
if either all elements of the stream match the
provided predicate or the stream is empty, otherwise false
public final boolean noneMatch(LongPredicate predicate)
LongStream
true
is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
noneMatch
in interface LongStream
predicate
- a non-interfering,
stateless
predicate to apply to elements of this streamtrue
if either no elements of the stream match the
provided predicate or the stream is empty, otherwise false
public final OptionalLong findFirst()
LongStream
OptionalLong
describing the first element of this
stream, or an empty OptionalLong
if the stream is empty. If the
stream has no encounter order, then any element may be returned.
This is a short-circuiting terminal operation.
findFirst
in interface LongStream
OptionalLong
describing the first element of this
stream, or an empty OptionalLong
if the stream is emptypublic final OptionalLong findAny()
LongStream
OptionalLong
describing some element of the stream, or
an empty OptionalLong
if the stream is empty.
This is a short-circuiting terminal operation.
The behavior of this operation is explicitly nondeterministic; it is
free to select any element in the stream. This is to allow for maximal
performance in parallel operations; the cost is that multiple invocations
on the same source may not return the same result. (If a stable result
is desired, use LongStream.findFirst()
instead.)
findAny
in interface LongStream
OptionalLong
describing some element of this stream,
or an empty OptionalLong
if the stream is emptyLongStream.findFirst()
public final long[] toArray()
LongStream
This is a terminal operation.
toArray
in interface LongStream