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

pack-priv abstract Class PipelineHelper<P_OUT>

extends Object
Class Inheritance
Known Direct Subclasses
java.util.stream.AbstractPipeline
Type Parameters
<P_OUT>
type of output elements from the pipeline
Imports
java.util.Spliterator, java.util.function.IntFunction

Helper class for executing stream pipelines, capturing all of the information about a stream pipeline (output shape, intermediate operations, stream flags, parallelism, etc) in one place.

A PipelineHelper describes the initial segment of a stream pipeline, including its source, intermediate operations, and may additionally incorporate information about the terminal (or stateful) operation which follows the last intermediate operation described by this PipelineHelper. The PipelineHelper is passed to the TerminalOp#evaluateParallel(PipelineHelper, java.util.Spliterator), TerminalOp#evaluateSequential(PipelineHelper, java.util.Spliterator), and AbstractPipeline#opEvaluateParallel(PipelineHelper, java.util.Spliterator, java.util.function.IntFunction), methods, which can use the PipelineHelper to access information about the pipeline such as head shape, stream flags, and size, and use the helper methods such as wrapAndCopyInto(Sink, Spliterator), copyInto(Sink, Spliterator), and wrapSink(Sink) to execute pipeline operations.

Since
1.8

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract <P_IN> void
copyInto(Sink<P_IN>
the destination Sink
wrappedSink
,
Spliterator<P_IN>
the source Spliterator
spliterator
)

Pushes elements obtained from the Spliterator into the provided Sink.

pack-priv abstract <P_IN> boolean

Returns:

true if the cancellation was requested
copyIntoWithCancel
(Sink<P_IN>
the destination Sink
wrappedSink
,
Spliterator<P_IN>
the source Spliterator
spliterator
)

Pushes elements obtained from the Spliterator into the provided Sink, checking Sink#cancellationRequested() after each element, and stopping if cancellation is requested.

pack-priv abstract <P_IN> Node<P_OUT>

Returns:

the Node containing all output elements
evaluate
(Spliterator<P_IN>
the source Spliterator
spliterator
,
boolean
if true and the pipeline is a parallel pipeline then the Node returned will contain no children, otherwise the Node may represent the root in a tree that reflects the shape of the computation tree.
flatten
,
IntFunction<P_OUT[]>
a factory function for array instances
generator
)

Collects all output elements resulting from applying the pipeline stages to the source Spliterator into a Node.

pack-priv abstract <P_IN> long

Returns:

the exact size if known, or -1 if infinite or unknown
exactOutputSizeIfKnown
(Spliterator<P_IN>
the spliterator describing the relevant portion of the source data
spliterator
)

Returns the exact output size of the portion of the output resulting from applying the pipeline stages described by this PipelineHelper to the portion of the input described by the provided Spliterator, if known.

pack-priv abstract StreamShape

Returns:

the stream shape for the source of the pipeline segment.
getSourceShape
()

Gets the stream shape for the source of the pipeline segment.

pack-priv abstract int

Returns:

the combined stream and operation flags
getStreamAndOpFlags
()

Gets the combined stream and operation flags for the output of the described pipeline.

pack-priv abstract Node.Builder<P_OUT>

Returns:

a Node.Builder compatible with the output shape of this PipelineHelper
makeNodeBuilder
(long
if >=0 then a builder will be created that has a fixed capacity of exactly sizeIfKnown elements; if < 0 then the builder has variable capacity. A fixed capacity builder will fail if an element is added after the builder has reached capacity.
exactSizeIfKnown
,
IntFunction<P_OUT[]>
a factory function for array instances
generator
)

Constructs a Node.Builder compatible with the output shape of this PipelineHelper.

pack-priv abstract <P_IN, S extends Sink<P_OUT>> S
wrapAndCopyInto(S
the Sink to receive the results
sink
,
Spliterator<P_IN>
the spliterator describing the source input to process
spliterator
)

Applies the pipeline stages described by this PipelineHelper to the provided Spliterator and send the results to the provided Sink.

pack-priv abstract <P_IN> Sink<P_IN>

Returns:

a Sink that implements the pipeline stages and sends results to the provided Sink
wrapSink
(Sink<P_OUT>
the Sink to receive the results
sink
)

Takes a Sink that accepts elements of the output type of the PipelineHelper, and wrap it with a Sink that accepts elements of the input type and implements all the intermediate operations described by this PipelineHelper, delivering the result into the provided Sink.

pack-priv abstract <P_IN> Spliterator<P_OUT>
wrapSpliterator(Spliterator<P_IN> spliterator)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PipelineHelperback to summary
pack-priv PipelineHelper()

Method Detail

copyIntoback to summary
pack-priv abstract <P_IN> void copyInto(Sink<P_IN> wrappedSink, Spliterator<P_IN> spliterator)

Pushes elements obtained from the Spliterator into the provided Sink. If the stream pipeline is known to have short-circuiting stages in it (see StreamOpFlag#SHORT_CIRCUIT), the Sink#cancellationRequested() is checked after each element, stopping if cancellation is requested.

Implementation Specification

This method conforms to the Sink protocol of calling Sink.begin before pushing elements, via Sink.accept, and calling Sink.end after all elements have been pushed.

Parameters
wrappedSink:Sink<P_IN>

the destination Sink

spliterator:Spliterator<P_IN>

the source Spliterator

copyIntoWithCancelback to summary
pack-priv abstract <P_IN> boolean copyIntoWithCancel(Sink<P_IN> wrappedSink, Spliterator<P_IN> spliterator)

Pushes elements obtained from the Spliterator into the provided Sink, checking Sink#cancellationRequested() after each element, and stopping if cancellation is requested.

Implementation Specification

This method conforms to the Sink protocol of calling Sink.begin before pushing elements, via Sink.accept, and calling Sink.end after all elements have been pushed or if cancellation is requested.

Parameters
wrappedSink:Sink<P_IN>

the destination Sink

spliterator:Spliterator<P_IN>

the source Spliterator

Returns:boolean

true if the cancellation was requested

evaluateback to summary
pack-priv abstract <P_IN> Node<P_OUT> evaluate(Spliterator<P_IN> spliterator, boolean flatten, IntFunction<P_OUT[]> generator)

Collects all output elements resulting from applying the pipeline stages to the source Spliterator into a Node.

Implementation Note

If the pipeline has no intermediate operations and the source is backed by a Node then that Node will be returned (or flattened and then returned). This reduces copying for a pipeline consisting of a stateful operation followed by a terminal operation that returns an array, such as:

stream.sorted().toArray();
Parameters
spliterator:Spliterator<P_IN>

the source Spliterator

flatten:boolean

if true and the pipeline is a parallel pipeline then the Node returned will contain no children, otherwise the Node may represent the root in a tree that reflects the shape of the computation tree.

generator:IntFunction<P_OUT[]>

a factory function for array instances

Returns:Node<P_OUT>

the Node containing all output elements

exactOutputSizeIfKnownback to summary
pack-priv abstract <P_IN> long exactOutputSizeIfKnown(Spliterator<P_IN> spliterator)

Returns the exact output size of the portion of the output resulting from applying the pipeline stages described by this PipelineHelper to the portion of the input described by the provided Spliterator, if known. If not known or known infinite, will return -1.

API Note

The exact output size is known if the Spliterator has the SIZED characteristic, and the operation flags StreamOpFlag#SIZED is known on the combined stream and operation flags. The exact output size may differ from spliterator size, if pipeline contains a slice operation.

Parameters
spliterator:Spliterator<P_IN>

the spliterator describing the relevant portion of the source data

Returns:long

the exact size if known, or -1 if infinite or unknown

getSourceShapeback to summary
pack-priv abstract StreamShape getSourceShape()

Gets the stream shape for the source of the pipeline segment.

Returns:StreamShape

the stream shape for the source of the pipeline segment.

getStreamAndOpFlagsback to summary
pack-priv abstract int getStreamAndOpFlags()

Gets the combined stream and operation flags for the output of the described pipeline. This will incorporate stream flags from the stream source, all the intermediate operations and the terminal operation.

Returns:int

the combined stream and operation flags

See Also
StreamOpFlag
makeNodeBuilderback to summary
pack-priv abstract Node.Builder<P_OUT> makeNodeBuilder(long exactSizeIfKnown, IntFunction<P_OUT[]> generator)

Constructs a Node.Builder compatible with the output shape of this PipelineHelper.

Parameters
exactSizeIfKnown:long

if >=0 then a builder will be created that has a fixed capacity of exactly sizeIfKnown elements; if < 0 then the builder has variable capacity. A fixed capacity builder will fail if an element is added after the builder has reached capacity.

generator:IntFunction<P_OUT[]>

a factory function for array instances

Returns:Node.Builder<P_OUT>

a Node.Builder compatible with the output shape of this PipelineHelper

wrapAndCopyIntoback to summary
pack-priv abstract <P_IN, S extends Sink<P_OUT>> S wrapAndCopyInto(S sink, Spliterator<P_IN> spliterator)

Applies the pipeline stages described by this PipelineHelper to the provided Spliterator and send the results to the provided Sink.

Implementation Specification

The implementation behaves as if:

copyInto(wrapSink(sink), spliterator);
Parameters
sink:S

the Sink to receive the results

spliterator:Spliterator<P_IN>

the spliterator describing the source input to process

wrapSinkback to summary
pack-priv abstract <P_IN> Sink<P_IN> wrapSink(Sink<P_OUT> sink)

Takes a Sink that accepts elements of the output type of the PipelineHelper, and wrap it with a Sink that accepts elements of the input type and implements all the intermediate operations described by this PipelineHelper, delivering the result into the provided Sink.

Parameters
sink:Sink<P_OUT>

the Sink to receive the results

Returns:Sink<P_IN>

a Sink that implements the pipeline stages and sends results to the provided Sink

wrapSpliteratorback to summary
pack-priv abstract <P_IN> Spliterator<P_OUT> wrapSpliterator(Spliterator<P_IN> spliterator)