E_IN
- type of elements in the upstream sourcepublic abstract class IntPipeline<E_IN> extends AbstractPipeline<E_IN,Integer,IntStream> implements IntStream
int
.Modifier and Type | Class and Description |
---|---|
static class |
IntPipeline.Head<E_IN>
Source stage of an IntStream.
|
static class |
IntPipeline.StatefulOp<E_IN>
Base class for a stateful intermediate stage of an IntStream.
|
static class |
IntPipeline.StatelessOp<E_IN>
Base class for a stateless intermediate stage of an IntStream
|
IntStream.Builder
sourceOrOpFlags
Modifier and Type | Method and Description |
---|---|
boolean |
allMatch(IntPredicate predicate)
Returns whether all elements of this stream match the provided predicate.
|
boolean |
anyMatch(IntPredicate 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 . |
LongStream |
asLongStream()
Returns a
LongStream consisting of the elements of this stream,
converted to long . |
OptionalDouble |
average()
Returns an
OptionalDouble describing the arithmetic mean of elements of
this stream, or an empty optional if this stream is empty. |
Stream<Integer> |
boxed()
Returns a
Stream consisting of the elements of this stream,
each boxed to an Integer . |
<R> R |
collect(Supplier<R> supplier,
ObjIntConsumer<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.
|
IntStream |
distinct()
Returns a stream consisting of the distinct elements of this stream.
|
<P_IN> Node<Integer> |
evaluateToNode(PipelineHelper<Integer> helper,
Spliterator<P_IN> spliterator,
boolean flattenTree,
IntFunction<Integer[]> generator)
Collect elements output from a pipeline into a Node that holds elements
of this shape.
|
IntStream |
filter(IntPredicate predicate)
Returns a stream consisting of the elements of this stream that match
the given predicate.
|
OptionalInt |
findAny()
Returns an
OptionalInt describing some element of the stream, or
an empty OptionalInt if the stream is empty. |
OptionalInt |
findFirst()
Returns an
OptionalInt describing the first element of this
stream, or an empty OptionalInt if the stream is empty. |
IntStream |
flatMap(IntFunction<? extends IntStream> 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(IntConsumer action)
Performs an action for each element of this stream.
|
void |
forEachOrdered(IntConsumer 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<Integer> spliterator,
Sink<Integer> 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.OfInt |
iterator()
Returns an iterator for the elements of this stream.
|
Spliterator.OfInt |
lazySpliterator(Supplier<? extends Spliterator<Integer>> supplier)
Create a lazy spliterator that wraps and obtains the supplied the
spliterator when a method is invoked on the lazy spliterator.
|
IntStream |
limit(long maxSize)
Returns a stream consisting of the elements of this stream, truncated
to be no longer than
maxSize in length. |
Node.Builder<Integer> |
makeNodeBuilder(long exactSizeIfKnown,
IntFunction<Integer[]> generator)
Make a node builder compatible with this stream shape.
|
IntStream |
map(IntUnaryOperator mapper)
Returns a stream consisting of the results of applying the given
function to the elements of this stream.
|
DoubleStream |
mapToDouble(IntToDoubleFunction mapper)
Returns a
DoubleStream consisting of the results of applying the
given function to the elements of this stream. |
LongStream |
mapToLong(IntToLongFunction mapper)
Returns a
LongStream consisting of the results of applying the
given function to the elements of this stream. |
<U> Stream<U> |
mapToObj(IntFunction<? extends U> mapper)
Returns an object-valued
Stream consisting of the results of
applying the given function to the elements of this stream. |
OptionalInt |
max()
Returns an
OptionalInt describing the maximum element of this
stream, or an empty optional if this stream is empty. |
OptionalInt |
min()
Returns an
OptionalInt describing the minimum element of this
stream, or an empty optional if this stream is empty. |
boolean |
noneMatch(IntPredicate predicate)
Returns whether no elements of this stream match the provided predicate.
|
IntStream |
peek(IntConsumer 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.
|
OptionalInt |
reduce(IntBinaryOperator op)
Performs a reduction on the
elements of this stream, using an
associative accumulation
function, and returns an
OptionalInt describing the reduced value,
if any. |
int |
reduce(int identity,
IntBinaryOperator 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.
|
IntStream |
skip(long n)
Returns a stream consisting of the remaining elements of this stream
after discarding the first
n elements of the stream. |
IntStream |
sorted()
Returns a stream consisting of the elements of this stream in sorted
order.
|
Spliterator.OfInt |
spliterator()
Returns a spliterator for the elements of this stream.
|
int |
sum()
Returns the sum of elements in this stream.
|
IntSummaryStatistics |
summaryStatistics()
Returns an
IntSummaryStatistics describing various
summary data about the elements of this stream. |
int[] |
toArray()
Returns an array containing the elements of this stream.
|
IntStream |
unordered()
Returns an equivalent stream that is
unordered.
|
<P_IN> Spliterator<Integer> |
wrap(PipelineHelper<Integer> 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,Integer,IntStream>
public final <P_IN> Node<Integer> evaluateToNode(PipelineHelper<Integer> helper, Spliterator<P_IN> spliterator, boolean flattenTree, IntFunction<Integer[]> generator)
AbstractPipeline
evaluateToNode
in class AbstractPipeline<E_IN,Integer,IntStream>
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<Integer> wrap(PipelineHelper<Integer> ph, Supplier<Spliterator<P_IN>> supplier, boolean isParallel)
AbstractPipeline
PipelineHelper
.wrap
in class AbstractPipeline<E_IN,Integer,IntStream>
ph
- the pipeline helper describing the pipeline stagessupplier
- the supplier of a spliteratorpublic final Spliterator.OfInt lazySpliterator(Supplier<? extends Spliterator<Integer>> supplier)
AbstractPipeline
lazySpliterator
in class AbstractPipeline<E_IN,Integer,IntStream>
supplier
- the supplier of a spliteratorpublic final void forEachWithCancel(Spliterator<Integer> spliterator, Sink<Integer> sink)
AbstractPipeline
forEachWithCancel
in class AbstractPipeline<E_IN,Integer,IntStream>
spliterator
- the spliterator to pull elements fromsink
- the sink to push elements topublic final Node.Builder<Integer> makeNodeBuilder(long exactSizeIfKnown, IntFunction<Integer[]> generator)
AbstractPipeline
makeNodeBuilder
in class AbstractPipeline<E_IN,Integer,IntStream>
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.OfInt iterator()
BaseStream
This is a terminal operation.
public final Spliterator.OfInt spliterator()
BaseStream
This is a terminal operation.
spliterator
in interface BaseStream<Integer,IntStream>
spliterator
in interface IntStream
spliterator
in class AbstractPipeline<E_IN,Integer,IntStream>
public final LongStream asLongStream()
IntStream
LongStream
consisting of the elements of this stream,
converted to long
.
This is an intermediate operation.
asLongStream
in interface IntStream
LongStream
consisting of the elements of this stream,
converted to long
public final DoubleStream asDoubleStream()
IntStream
DoubleStream
consisting of the elements of this stream,
converted to double
.
This is an intermediate operation.
asDoubleStream
in interface IntStream
DoubleStream
consisting of the elements of this stream,
converted to double
public final Stream<Integer> boxed()
IntStream
Stream
consisting of the elements of this stream,
each boxed to an Integer
.
This is an intermediate operation.
public final IntStream map(IntUnaryOperator mapper)
IntStream
This is an intermediate operation.
map
in interface IntStream
mapper
- a non-interfering,
stateless
function to apply to each elementpublic final <U> Stream<U> mapToObj(IntFunction<? extends U> mapper)
IntStream
Stream
consisting of the results of
applying the given function to the elements of this stream.
This is an intermediate operation.
mapToObj
in interface IntStream
U
- the element type of the new streammapper
- a non-interfering,
stateless
function to apply to each elementpublic final LongStream mapToLong(IntToLongFunction mapper)
IntStream
LongStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToLong
in interface IntStream
mapper
- a non-interfering,
stateless
function to apply to each elementpublic final DoubleStream mapToDouble(IntToDoubleFunction mapper)
IntStream
DoubleStream
consisting of the results of applying the
given function to the elements of this stream.
This is an intermediate operation.
mapToDouble
in interface IntStream
mapper
- a non-interfering,
stateless
function to apply to each elementpublic final IntStream flatMap(IntFunction<? extends IntStream> mapper)
IntStream
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 IntStream
mapper
- a non-interfering,
stateless
function to apply to each element which produces an
IntStream
of new valuesStream.flatMap(Function)
public IntStream unordered()
BaseStream
This is an intermediate operation.
unordered
in interface BaseStream<Integer,IntStream>
public final IntStream filter(IntPredicate predicate)
IntStream
This is an intermediate operation.
filter
in interface IntStream
predicate
- a non-interfering,
stateless
predicate to apply to each element to determine if it
should be includedpublic final IntStream peek(IntConsumer action)
IntStream
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 IntStream
action
- a
non-interfering action to perform on the elements as
they are consumed from the streampublic final IntStream limit(long maxSize)
IntStream
maxSize
in length.
public final IntStream skip(long n)
IntStream
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.
public final IntStream sorted()
IntStream
This is a stateful intermediate operation.
public final IntStream distinct()
IntStream
This is a stateful intermediate operation.
public void forEach(IntConsumer action)
IntStream
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 IntStream
action
- a
non-interfering action to perform on the elementspublic void forEachOrdered(IntConsumer action)
IntStream
This is a terminal operation.
forEachOrdered
in interface IntStream
action
- a
non-interfering action to perform on the elementsIntStream.forEach(IntConsumer)
public final int sum()
IntStream
return reduce(0, Integer::sum);
This is a terminal operation.
public final OptionalInt min()
IntStream
OptionalInt
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(Integer::min);
This is a terminal operation.
public final OptionalInt max()
IntStream
OptionalInt
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(Integer::max);
This is a terminal operation.
public final long count()
IntStream
return mapToLong(e -> 1L).sum();
This is a terminal operation.
public final OptionalDouble average()
IntStream
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.
public final IntSummaryStatistics summaryStatistics()
IntStream
IntSummaryStatistics
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 IntStream
IntSummaryStatistics
describing various summary data
about the elements of this streampublic final int reduce(int identity, IntBinaryOperator op)
IntStream
int result = identity;
for (int element : this stream)
result = accumulator.applyAsInt(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 IntStream
identity
- the identity value for the accumulating functionop
- an associative,
non-interfering,
stateless
function for combining two valuesIntStream.sum()
,
IntStream.min()
,
IntStream.max()
,
IntStream.average()
public final OptionalInt reduce(IntBinaryOperator op)
IntStream
OptionalInt
describing the reduced value,
if any. This is equivalent to:
boolean foundAny = false;
int result = null;
for (int element : this stream) {
if (!foundAny) {
foundAny = true;
result = element;
}
else
result = accumulator.applyAsInt(result, element);
}
return foundAny ? OptionalInt.of(result) : OptionalInt.empty();
but is not constrained to execute sequentially.
The accumulator
function must be an
associative function.
This is a terminal operation.
reduce
in interface IntStream
op
- an associative,
non-interfering,
stateless
function for combining two valuesIntStream.reduce(int, IntBinaryOperator)
public final <R> R collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R,R> combiner)
IntStream
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 (int element : this stream)
accumulator.accept(result, element);
return result;
Like IntStream.reduce(int, IntBinaryOperator)
, collect
operations
can be parallelized without requiring additional synchronization.
This is a terminal operation.
collect
in interface IntStream
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(IntPredicate predicate)
IntStream
false
is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
anyMatch
in interface IntStream
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(IntPredicate predicate)
IntStream
true
is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
allMatch
in interface IntStream
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(IntPredicate predicate)
IntStream
true
is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
noneMatch
in interface IntStream
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 OptionalInt findFirst()
IntStream
OptionalInt
describing the first element of this
stream, or an empty OptionalInt
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.
public final OptionalInt findAny()
IntStream
OptionalInt
describing some element of the stream, or
an empty OptionalInt
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 IntStream.findFirst()
instead.)
findAny
in interface IntStream
OptionalInt
describing some element of this stream, or
an empty OptionalInt
if the stream is emptyIntStream.findFirst()
public final int[] toArray()
IntStream
This is a terminal operation.