APIdia Launch Partner
Top Description Inners Constructors Methods
java.util.stream

pack-priv final Class ForEachOps

extends Object
Class Inheritance
Imports
jdk.internal.invoke.MhUtil, java.util.Objects, .Spliterator, java.util.concurrent.CountedCompleter, java.util.function.Consumer, .DoubleConsumer, .IntConsumer, .IntFunction, .LongConsumer, java.lang.invoke.VarHandle, .MethodHandles

Factory for creating instances of TerminalOp that perform an action for every element of a stream. Supported variants include unordered traversal (elements are provided to the Consumer as soon as they are available), and ordered traversal (elements are provided to the Consumer in encounter order.)

Elements are provided to the Consumer on whatever thread and whatever order they become available. For ordered traversals, it is guaranteed that processing an element happens-before processing subsequent elements in the encounter order.

Exceptions occurring as a result of sending an element to the Consumer will be relayed to the caller and traversal will be prematurely terminated.

Since
1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
ForEachOps.ForEachOp<
the output type of the stream pipeline
T
>

A TerminalOp that evaluates a stream pipeline and sends the output to itself as a TerminalSink.

pack-priv static class
ForEachOps.ForEachOrderedTask<S, T>

A ForkJoinTask for performing a parallel for-each operation which visits the elements in encounter order

pack-priv static class
ForEachOps.ForEachTask<S, T>

A ForkJoinTask for performing a parallel for-each operation

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static TerminalOp<Double, Void>

Returns:

the TerminalOp instance
makeDouble
(DoubleConsumer
the DoubleConsumer that receives all elements of a stream
action
,
boolean
whether an ordered traversal is requested
ordered
)

Constructs a TerminalOp that perform an action for every element of a DoubleStream.

public static TerminalOp<Integer, Void>

Returns:

the TerminalOp instance
makeInt
(IntConsumer
the IntConsumer that receives all elements of a stream
action
,
boolean
whether an ordered traversal is requested
ordered
)

Constructs a TerminalOp that perform an action for every element of an IntStream.

public static TerminalOp<Long, Void>

Returns:

the TerminalOp instance
makeLong
(LongConsumer
the LongConsumer that receives all elements of a stream
action
,
boolean
whether an ordered traversal is requested
ordered
)

Constructs a TerminalOp that perform an action for every element of a LongStream.

public static <
the type of the stream elements
T
>
TerminalOp<T, Void>

Returns:

the TerminalOp instance
makeRef
(Consumer<? super T>
the Consumer that receives all elements of a stream
action
,
boolean
whether an ordered traversal is requested
ordered
)

Constructs a TerminalOp that perform an action for every element of a stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ForEachOpsback to summary
private ForEachOps()

Method Detail

makeDoubleback to summary
public static TerminalOp<Double, Void> makeDouble(DoubleConsumer action, boolean ordered)

Constructs a TerminalOp that perform an action for every element of a DoubleStream.

Parameters
action:DoubleConsumer

the DoubleConsumer that receives all elements of a stream

ordered:boolean

whether an ordered traversal is requested

Returns:TerminalOp<Double, Void>

the TerminalOp instance

makeIntback to summary
public static TerminalOp<Integer, Void> makeInt(IntConsumer action, boolean ordered)

Constructs a TerminalOp that perform an action for every element of an IntStream.

Parameters
action:IntConsumer

the IntConsumer that receives all elements of a stream

ordered:boolean

whether an ordered traversal is requested

Returns:TerminalOp<Integer, Void>

the TerminalOp instance

makeLongback to summary
public static TerminalOp<Long, Void> makeLong(LongConsumer action, boolean ordered)

Constructs a TerminalOp that perform an action for every element of a LongStream.

Parameters
action:LongConsumer

the LongConsumer that receives all elements of a stream

ordered:boolean

whether an ordered traversal is requested

Returns:TerminalOp<Long, Void>

the TerminalOp instance

makeRefback to summary
public static <T> TerminalOp<T, Void> makeRef(Consumer<? super T> action, boolean ordered)

Constructs a TerminalOp that perform an action for every element of a stream.

Parameters
<T>
the type of the stream elements
action:Consumer<? super T>

the Consumer that receives all elements of a stream

ordered:boolean

whether an ordered traversal is requested

Returns:TerminalOp<T, Void>

the TerminalOp instance

java.util.stream back to summary

pack-priv abstract Class ForEachOps.ForEachOp<T>

extends Object
implements TerminalOp<T, Void>, TerminalSink<T, Void>
Class Inheritance
All Implemented Interfaces
java.util.stream.TerminalSink, java.util.function.Supplier, java.util.stream.Sink, java.util.function.Consumer, java.util.stream.TerminalOp
Known Direct Subclasses
java.util.stream.ForEachOps.ForEachOp.OfRef, java.util.stream.ForEachOps.ForEachOp.OfInt, java.util.stream.ForEachOps.ForEachOp.OfLong, java.util.stream.ForEachOps.ForEachOp.OfDouble
Type Parameters
<T>
the output type of the stream pipeline

A TerminalOp that evaluates a stream pipeline and sends the output to itself as a TerminalSink. Elements will be sent in whatever thread they become available. If the traversal is unordered, they will be sent independent of the stream's encounter order.

This terminal operation is stateless. For parallel evaluation, each leaf instance of a ForEachTask will send elements to the same TerminalSink reference that is an instance of this class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ForEachOps.ForEachOp.OfDouble

Implementation class for DoubleStream

pack-priv static class
ForEachOps.ForEachOp.OfInt

Implementation class for IntStream

pack-priv static class
ForEachOps.ForEachOp.OfLong

Implementation class for LongStream

pack-priv static class
ForEachOps.ForEachOp.OfRef<T>

Implementation class for reference streams

Field Summary

Modifier and TypeField and Description
private final boolean

Constructor Summary

AccessConstructor and Description
protected
ForEachOp(boolean ordered)

Method Summary

Modifier and TypeMethod and Description
public <S> Void
evaluateParallel(PipelineHelper<T> helper, Spliterator<S> spliterator)

Overrides default java.util.stream.TerminalOp.evaluateParallel.

Performs a parallel evaluation of the operation using the specified PipelineHelper, which describes the upstream intermediate operations.

public <S> Void
evaluateSequential(PipelineHelper<T> helper, Spliterator<S> spliterator)

Implements java.util.stream.TerminalOp.evaluateSequential.

Performs a sequential evaluation of the operation using the specified PipelineHelper, which describes the upstream intermediate operations.

public Void
get()

Implements java.util.function.Supplier.get.

Gets a result.

public int
getOpFlags()

Overrides default java.util.stream.TerminalOp.getOpFlags.

Gets the stream flags of the operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

orderedback to summary
private final boolean ordered

Constructor Detail

ForEachOpback to summary
protected ForEachOp(boolean ordered)

Method Detail

evaluateParallelback to summary
public <S> Void evaluateParallel(PipelineHelper<T> helper, Spliterator<S> spliterator)

Overrides default java.util.stream.TerminalOp.evaluateParallel.

Doc from java.util.stream.TerminalOp.evaluateParallel.

Performs a parallel evaluation of the operation using the specified PipelineHelper, which describes the upstream intermediate operations.

Annotations
@Override
evaluateSequentialback to summary
public <S> Void evaluateSequential(PipelineHelper<T> helper, Spliterator<S> spliterator)

Implements java.util.stream.TerminalOp.evaluateSequential.

Doc from java.util.stream.TerminalOp.evaluateSequential.

Performs a sequential evaluation of the operation using the specified PipelineHelper, which describes the upstream intermediate operations.

Annotations
@Override
getback to summary
public Void get()

Implements java.util.function.Supplier.get.

Doc from java.util.function.Supplier.get.

Gets a result.

Annotations
@Override
getOpFlagsback to summary
public int getOpFlags()

Overrides default java.util.stream.TerminalOp.getOpFlags.

Doc from java.util.stream.TerminalOp.getOpFlags.

Gets the stream flags of the operation. Terminal operations may set a limited subset of the stream flags defined in StreamOpFlag, and these flags are combined with the previously combined stream and intermediate operation flags for the pipeline.

Annotations
@Override
java.util.stream back to summary

pack-priv final Class ForEachOps.ForEachOp.OfDouble

extends ForEachOps.ForEachOp<Double>
implements OfDouble
Class Inheritance
All Implemented Interfaces
java.util.stream.Sink.OfDouble, java.util.function.DoubleConsumer, java.util.stream.Sink, java.util.function.Consumer

Implementation class for DoubleStream

Field Summary

Modifier and TypeField and Description
pack-priv final DoubleConsumer

Constructor Summary

AccessConstructor and Description
pack-priv
OfDouble(DoubleConsumer consumer, boolean ordered)

Method Summary

Modifier and TypeMethod and Description
public void
accept(double t)

Overrides default java.util.stream.Sink.accept.

Implements java.util.stream.Sink.OfDouble.accept.

Accepts a double value.

public StreamShape
inputShape()

Overrides default java.util.stream.TerminalOp.inputShape.

Gets the shape of the input type of this operation.

Inherited from java.util.stream.ForEachOps.ForEachOp:
evaluateParallelevaluateSequentialgetgetOpFlags

Field Detail

consumerback to summary
pack-priv final DoubleConsumer consumer

Constructor Detail

OfDoubleback to summary
pack-priv OfDouble(DoubleConsumer consumer, boolean ordered)

Method Detail

acceptback to summary
public void accept(double t)

Overrides default java.util.stream.Sink.accept.

Implements java.util.stream.Sink.OfDouble.accept.

Doc from java.util.stream.Sink.accept.

Accepts a double value.

Annotations
@Override
inputShapeback to summary
public StreamShape inputShape()

Overrides default java.util.stream.TerminalOp.inputShape.

Doc from java.util.stream.TerminalOp.inputShape.

Gets the shape of the input type of this operation.

Annotations
@Override
java.util.stream back to summary

pack-priv final Class ForEachOps.ForEachOp.OfInt

extends ForEachOps.ForEachOp<Integer>
implements OfInt
Class Inheritance
All Implemented Interfaces
java.util.stream.Sink.OfInt, java.util.function.IntConsumer, java.util.stream.Sink, java.util.function.Consumer

Implementation class for IntStream

Field Summary

Modifier and TypeField and Description
pack-priv final IntConsumer

Constructor Summary

AccessConstructor and Description
pack-priv
OfInt(IntConsumer consumer, boolean ordered)

Method Summary

Modifier and TypeMethod and Description
public void
accept(int t)

Overrides default java.util.stream.Sink.accept.

Implements java.util.stream.Sink.OfInt.accept.

Accepts an int value.

public StreamShape
inputShape()

Overrides default java.util.stream.TerminalOp.inputShape.

Gets the shape of the input type of this operation.

Inherited from java.util.stream.ForEachOps.ForEachOp:
evaluateParallelevaluateSequentialgetgetOpFlags

Field Detail

consumerback to summary
pack-priv final IntConsumer consumer

Constructor Detail

OfIntback to summary
pack-priv OfInt(IntConsumer consumer, boolean ordered)

Method Detail

acceptback to summary
public void accept(int t)

Overrides default java.util.stream.Sink.accept.

Implements java.util.stream.Sink.OfInt.accept.

Doc from java.util.stream.Sink.accept.

Accepts an int value.

Annotations
@Override
inputShapeback to summary
public StreamShape inputShape()

Overrides default java.util.stream.TerminalOp.inputShape.

Doc from java.util.stream.TerminalOp.inputShape.

Gets the shape of the input type of this operation.

Annotations
@Override
java.util.stream back to summary

pack-priv final Class ForEachOps.ForEachOp.OfLong

extends ForEachOps.ForEachOp<Long>
implements OfLong
Class Inheritance
All Implemented Interfaces
java.util.stream.Sink.OfLong, java.util.function.LongConsumer, java.util.stream.Sink, java.util.function.Consumer

Implementation class for LongStream

Field Summary

Modifier and TypeField and Description
pack-priv final LongConsumer

Constructor Summary

AccessConstructor and Description
pack-priv
OfLong(LongConsumer consumer, boolean ordered)

Method Summary

Modifier and TypeMethod and Description
public void
accept(long t)

Overrides default java.util.stream.Sink.accept.

Implements java.util.stream.Sink.OfLong.accept.

Accepts a long value.

public StreamShape
inputShape()

Overrides default java.util.stream.TerminalOp.inputShape.

Gets the shape of the input type of this operation.

Inherited from java.util.stream.ForEachOps.ForEachOp:
evaluateParallelevaluateSequentialgetgetOpFlags

Field Detail

consumerback to summary
pack-priv final LongConsumer consumer

Constructor Detail

OfLongback to summary
pack-priv OfLong(LongConsumer consumer, boolean ordered)

Method Detail

acceptback to summary
public void accept(long t)

Overrides default java.util.stream.Sink.accept.

Implements java.util.stream.Sink.OfLong.accept.

Doc from java.util.stream.Sink.accept.

Accepts a long value.

Annotations
@Override
inputShapeback to summary
public StreamShape inputShape()

Overrides default java.util.stream.TerminalOp.inputShape.

Doc from java.util.stream.TerminalOp.inputShape.

Gets the shape of the input type of this operation.

Annotations
@Override
java.util.stream back to summary

pack-priv final Class ForEachOps.ForEachOp.OfRef<T>

extends ForEachOps.ForEachOp<T>
Class Inheritance

Implementation class for reference streams

Field Summary

Modifier and TypeField and Description
pack-priv final Consumer<? super T>

Constructor Summary

AccessConstructor and Description
pack-priv
OfRef(Consumer<? super T> consumer, boolean ordered)

Method Summary

Modifier and TypeMethod and Description
public void
accept(T t)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.

Inherited from java.util.stream.ForEachOps.ForEachOp:
evaluateParallelevaluateSequentialgetgetOpFlags

Field Detail

consumerback to summary
pack-priv final Consumer<? super T> consumer

Constructor Detail

OfRefback to summary
pack-priv OfRef(Consumer<? super T> consumer, boolean ordered)

Method Detail

acceptback to summary
public void accept(T t)

Implements java.util.function.Consumer.accept.

Doc from java.util.function.Consumer.accept.

Performs this operation on the given argument.

Annotations
@Override
java.util.stream back to summary

pack-priv final Class ForEachOps.ForEachOrderedTask<S, T>

extends CountedCompleter<Void>
Class Inheritance
Annotations
@SuppressWarnings:serial

A ForkJoinTask for performing a parallel for-each operation which visits the elements in encounter order

Field Summary

Modifier and TypeField and Description
private final Sink<T>
private final PipelineHelper<T>
private final ForEachOps.ForEachOrderedTask<S, T>
private ForEachOps.ForEachOrderedTask<S, T>
private static final VarHandle
private Node<T>
private Spliterator<S>
private final long

Constructor Summary

AccessConstructor and Description
protected
ForEachOrderedTask(PipelineHelper<T> helper, Spliterator<S> spliterator, Sink<T> action)

pack-priv
ForEachOrderedTask(ForEachOps.ForEachOrderedTask<S, T> parent, Spliterator<S> spliterator, ForEachOps.ForEachOrderedTask<S, T> leftPredecessor)

Method Summary

Modifier and TypeMethod and Description
public final void
compute()

Implements abstract java.util.concurrent.CountedCompleter.compute.

The main computation performed by this task.

private static <S, T> void
public void
onCompletion(CountedCompleter<?> caller)

Overrides java.util.concurrent.CountedCompleter.onCompletion.

Performs an action when method tryComplete is invoked and the pending count is zero, or when the unconditional method complete is invoked.

Inherited from java.util.concurrent.CountedCompleter:
addToPendingCountcompareAndSetPendingCountcompletedecrementPendingCountUnlessZeroexecfirstCompletegetCompletergetPendingCountgetRawResultgetRoothelpCompletenextCompleteonExceptionalCompletionpropagateCompletionquietlyCompleteRootsetPendingCountsetRawResulttryComplete

Field Detail

actionback to summary
private final Sink<T> action
helperback to summary
private final PipelineHelper<T> helper
leftPredecessorback to summary
private final ForEachOps.ForEachOrderedTask<S, T> leftPredecessor
nextback to summary
private ForEachOps.ForEachOrderedTask<S, T> next
NEXTback to summary
private static final VarHandle NEXT
nodeback to summary
private Node<T> node
spliteratorback to summary
private Spliterator<S> spliterator
targetSizeback to summary
private final long targetSize

Constructor Detail

ForEachOrderedTaskback to summary
protected ForEachOrderedTask(PipelineHelper<T> helper, Spliterator<S> spliterator, Sink<T> action)
ForEachOrderedTaskback to summary
pack-priv ForEachOrderedTask(ForEachOps.ForEachOrderedTask<S, T> parent, Spliterator<S> spliterator, ForEachOps.ForEachOrderedTask<S, T> leftPredecessor)

Method Detail

computeback to summary
public final void compute()

Implements abstract java.util.concurrent.CountedCompleter.compute.

Doc from java.util.concurrent.CountedCompleter.compute.

The main computation performed by this task.

Annotations
@Override
doComputeback to summary
private static <S, T> void doCompute(ForEachOps.ForEachOrderedTask<S, T> task)
onCompletionback to summary
public void onCompletion(CountedCompleter<?> caller)

Overrides java.util.concurrent.CountedCompleter.onCompletion.

Doc from java.util.concurrent.CountedCompleter.onCompletion.

Performs an action when method tryComplete is invoked and the pending count is zero, or when the unconditional method complete is invoked. By default, this method does nothing. You can distinguish cases by checking the identity of the given caller argument. If not equal to this, then it is typically a subtask that may contain results (and/or links to other results) to combine.

Annotations
@Override
java.util.stream back to summary

pack-priv final Class ForEachOps.ForEachTask<S, T>

extends CountedCompleter<Void>
Class Inheritance
Annotations
@SuppressWarnings:serial

A ForkJoinTask for performing a parallel for-each operation

Field Summary

Modifier and TypeField and Description
private final PipelineHelper<T>
private final Sink<S>
private Spliterator<S>
private long

Constructor Summary

AccessConstructor and Description
pack-priv
ForEachTask(PipelineHelper<T> helper, Spliterator<S> spliterator, Sink<S> sink)

pack-priv
ForEachTask(ForEachOps.ForEachTask<S, T> parent, Spliterator<S> spliterator)

Method Summary

Modifier and TypeMethod and Description
public void
compute()

Implements abstract java.util.concurrent.CountedCompleter.compute.

The main computation performed by this task.

Inherited from java.util.concurrent.CountedCompleter:
addToPendingCountcompareAndSetPendingCountcompletedecrementPendingCountUnlessZeroexecfirstCompletegetCompletergetPendingCountgetRawResultgetRoothelpCompletenextCompleteonCompletiononExceptionalCompletionpropagateCompletionquietlyCompleteRootsetPendingCountsetRawResulttryComplete

Field Detail

helperback to summary
private final PipelineHelper<T> helper
sinkback to summary
private final Sink<S> sink
spliteratorback to summary
private Spliterator<S> spliterator
targetSizeback to summary
private long targetSize

Constructor Detail

ForEachTaskback to summary
pack-priv ForEachTask(PipelineHelper<T> helper, Spliterator<S> spliterator, Sink<S> sink)
ForEachTaskback to summary
pack-priv ForEachTask(ForEachOps.ForEachTask<S, T> parent, Spliterator<S> spliterator)

Method Detail

computeback to summary
public void compute()

Implements abstract java.util.concurrent.CountedCompleter.compute.

Doc from java.util.concurrent.CountedCompleter.compute.

The main computation performed by this task.