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

pack-priv final Class GathererOp<T, A, R>

extends ReferencePipeline<T, R>
Class Inheritance
Imports
jdk.internal.invoke.MhUtil, jdk.internal.vm.annotation.ForceInline, java.lang.invoke.MethodHandles, .VarHandle, java.util.Spliterator, java.util.concurrent.CountedCompleter, java.util.concurrent.atomic.AtomicBoolean, java.util.function.BiConsumer, .BinaryOperator, .Consumer, .Function, .IntFunction, .Supplier, java.util.stream.Gatherer.Integrator

Runtime machinery for evaluating Gatherers under different modes. The performance-critical code below contains some more complicated encodings: therefore, make sure to run benchmarks to verify changes to prevent regressions.
Since
24

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv final Gatherer<T, A, R>
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private
GathererOp(ReferencePipeline<?, T> upstream, Gatherer<T, A, R> gatherer)

private
GathererOp(Gatherer<T, A, R> gatherer, GathererOp<?, ?, T> upstream)

Method Summary

Modifier and TypeMethod and Description
public <CR, CA> CR
collect(Collector<? super R, CA, CR> c)

Overrides java.util.stream.ReferencePipeline.collect.

Implements java.util.stream.Stream.collect.

Performs a mutable reduction operation on the elements of this stream using a Collector.

public <RR> RR
collect(Supplier<RR> supplier, BiConsumer<RR, ? super R> accumulator, BiConsumer<RR, RR> combiner)

Overrides java.util.stream.ReferencePipeline.collect.

Implements java.util.stream.Stream.collect.

Performs a mutable reduction operation on the elements of this stream.

private <CA, CR> CR
evaluate(final Spliterator<T> spliterator, final boolean parallel, final Gatherer<T, A, R> gatherer, final Supplier<CA> collectorSupplier, final BiConsumer<CA, ? super R> collectorAccumulator, final BinaryOperator<CA> collectorCombiner, final Function<CA, CR> collectorFinisher)

pack-priv static <P_IN, P_OUT extends T, T, A, R> Stream<R>
of(ReferencePipeline<P_IN, P_OUT> upstream, Gatherer<T, A, R> gatherer)

pack-priv <I> Node<R>
opEvaluateParallel(PipelineHelper<R> unused1, Spliterator<I> spliterator, IntFunction<R[]> unused2)

Overrides java.util.stream.AbstractPipeline.opEvaluateParallel.

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

pack-priv <P_IN> Spliterator<R>
opEvaluateParallelLazy(PipelineHelper<R> helper, Spliterator<P_IN> spliterator)

Overrides java.util.stream.AbstractPipeline.opEvaluateParallelLazy.

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

private static int
opFlagsFor(Gatherer.Integrator<?, ?, ?> integrator)

pack-priv boolean
opIsStateful()

Implements abstract java.util.stream.AbstractPipeline.opIsStateful.

Returns whether this operation is stateful or not.

pack-priv Sink<T>
opWrapSink(int flags, Sink<R> downstream)

Implements abstract java.util.stream.AbstractPipeline.opWrapSink.

Accepts a Sink which will receive the results of this operation, and return a Sink which accepts elements of the input type of this operation and which performs the operation, passing the results to the provided Sink.

private AbstractPipeline<?, T, ?>
Inherited from java.util.stream.ReferencePipeline:
allMatchanyMatchcountdistinctdropWhileevaluateToNodefilterfindAnyfindFirstflatMapflatMapToDoubleflatMapToIntflatMapToLongforEachforEachOrderedforEachWithCancelgathergetOutputShapeiteratorlazySpliteratorlimitmakeNodeBuildermapmapMultimapMultiToDoublemapMultiToIntmapMultiToLongmapToDoublemapToIntmapToLongmaxminnoneMatchpeekreducereducereduceskipsortedsortedtakeWhiletoArraytoArraytoListunorderedwrap

Field Detail

DEFAULT_FLAGSback to summary
private static final int DEFAULT_FLAGS
gathererback to summary
pack-priv final Gatherer<T, A, R> gatherer
GREEDY_FLAGSback to summary
private static final int GREEDY_FLAGS
SHORT_CIRCUIT_FLAGSback to summary
private static final int SHORT_CIRCUIT_FLAGS

Constructor Detail

GathererOpback to summary
private GathererOp(ReferencePipeline<?, T> upstream, Gatherer<T, A, R> gatherer)
GathererOpback to summary
private GathererOp(Gatherer<T, A, R> gatherer, GathererOp<?, ?, T> upstream)
Annotations
@SuppressWarnings:unchecked

Method Detail

collectback to summary
public <CR, CA> CR collect(Collector<? super R, CA, CR> c)

Overrides java.util.stream.ReferencePipeline.collect.

Implements java.util.stream.Stream.collect.

Doc from java.util.stream.Stream.collect.

Performs a mutable reduction operation on the elements of this stream using a Collector. A Collector encapsulates the functions used as arguments to collect(Supplier, BiConsumer, BiConsumer), allowing for reuse of collection strategies and composition of collect operations such as multiple-level grouping or partitioning.

If the stream is parallel, and the Collector is concurrent, and either the stream is unordered or the collector is unordered, then a concurrent reduction will be performed (see Collector for details on concurrent reduction.)

This is a terminal operation.

When executed in parallel, multiple intermediate results may be instantiated, populated, and merged so as to maintain isolation of mutable data structures. Therefore, even when executed in parallel with non-thread-safe data structures (such as ArrayList), no additional synchronization is needed for a parallel reduction.

Annotations
@Override
collectback to summary
public <RR> RR collect(Supplier<RR> supplier, BiConsumer<RR, ? super R> accumulator, BiConsumer<RR, RR> combiner)

Overrides java.util.stream.ReferencePipeline.collect.

Implements java.util.stream.Stream.collect.

Doc from java.util.stream.Stream.collect.

Performs a mutable reduction operation on the elements of this stream. A mutable reduction is one in which the reduced value is a mutable result container, such as an 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 (T element : this stream)
        accumulator.accept(result, element);
    return result;

Like reduce(Object, BinaryOperator), collect operations can be parallelized without requiring additional synchronization.

This is a terminal operation.

Annotations
@Override
evaluateback to summary
private <CA, CR> CR evaluate(final Spliterator<T> spliterator, final boolean parallel, final Gatherer<T, A, R> gatherer, final Supplier<CA> collectorSupplier, final BiConsumer<CA, ? super R> collectorAccumulator, final BinaryOperator<CA> collectorCombiner, final Function<CA, CR> collectorFinisher)
ofback to summary
pack-priv static <P_IN, P_OUT extends T, T, A, R> Stream<R> of(ReferencePipeline<P_IN, P_OUT> upstream, Gatherer<T, A, R> gatherer)
Annotations
@SuppressWarnings:unchecked
opEvaluateParallelback to summary
pack-priv <I> Node<R> opEvaluateParallel(PipelineHelper<R> unused1, Spliterator<I> spliterator, IntFunction<R[]> unused2)

Overrides java.util.stream.AbstractPipeline.opEvaluateParallel.

Doc from java.util.stream.AbstractPipeline.opEvaluateParallel.

Performs a parallel evaluation of the operation using the specified PipelineHelper which describes the upstream intermediate operations. Only called on stateful operations. If opIsStateful() returns true then implementations must override the default implementation.

Annotations
@Override
opEvaluateParallelLazyback to summary
pack-priv <P_IN> Spliterator<R> opEvaluateParallelLazy(PipelineHelper<R> helper, Spliterator<P_IN> spliterator)

Overrides java.util.stream.AbstractPipeline.opEvaluateParallelLazy.

Doc from java.util.stream.AbstractPipeline.opEvaluateParallelLazy.

Returns a Spliterator describing a parallel evaluation of the operation, using the specified PipelineHelper which describes the upstream intermediate operations. Only called on stateful operations. It is not necessary (though acceptable) to do a full computation of the result here; it is preferable, if possible, to describe the result via a lazily evaluated spliterator.

Annotations
@Override
opFlagsForback to summary
private static int opFlagsFor(Gatherer.Integrator<?, ?, ?> integrator)
opIsStatefulback to summary
pack-priv boolean opIsStateful()

Implements abstract java.util.stream.AbstractPipeline.opIsStateful.

Doc from java.util.stream.AbstractPipeline.opIsStateful.

Returns whether this operation is stateful or not. If it is stateful, then the method opEvaluateParallel(PipelineHelper, java.util.Spliterator, java.util.function.IntFunction) must be overridden.

Annotations
@Override
opWrapSinkback to summary
pack-priv Sink<T> opWrapSink(int flags, Sink<R> downstream)

Implements abstract java.util.stream.AbstractPipeline.opWrapSink.

Doc from java.util.stream.AbstractPipeline.opWrapSink.

Accepts a Sink which will receive the results of this operation, and return a Sink which accepts elements of the input type of this operation and which performs the operation, passing the results to the provided Sink.

Annotations
@Override
upstreamback to summary
private AbstractPipeline<?, T, ?> upstream()
Annotations
@SuppressWarnings:unchecked
java.util.stream back to summary

pack-priv final Class GathererOp.GatherSink<T, A, R>

extends Object
implements Sink<T>, Gatherer.Downstream<R>
Class Inheritance
All Implemented Interfaces
java.util.stream.Gatherer.Downstream, java.util.stream.Sink, java.util.function.Consumer

Field Summary

Modifier and TypeField and Description
private boolean
private final Gatherer<T, A, R>
private final Gatherer.Integrator<A, T, R>
private boolean
private final Sink<R>
private A

Constructor Summary

AccessConstructor and Description
pack-priv
GatherSink(Gatherer<T, A, R> gatherer, Sink<R> sink)

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.

public void
begin(long size)

Overrides default java.util.stream.Sink.begin.

Resets the sink state to receive a fresh data set.

public boolean
cancellationRequested()

Overrides default java.util.stream.Sink.cancellationRequested.

Indicates that this Sink does not wish to receive any more data.

private boolean
cancellationRequested(boolean knownProceed)

public void
end()

Overrides default java.util.stream.Sink.end.

Indicates that all elements have been pushed.

public boolean
isRejecting()

Overrides default java.util.stream.Gatherer.Downstream.isRejecting.

Checks whether the next stage is known to not want any more elements sent to it.

public boolean
push(R r)

Implements java.util.stream.Gatherer.Downstream.push.

Pushes, if possible, the provided element downstream -- to the next stage in the pipeline.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

downstreamProceedback to summary
private boolean downstreamProceed
gathererback to summary
private final Gatherer<T, A, R> gatherer
integratorback to summary
private final Gatherer.Integrator<A, T, R> integrator
proceedback to summary
private boolean proceed
sinkback to summary
private final Sink<R> sink
stateback to summary
private A state

Constructor Detail

GatherSinkback to summary
pack-priv GatherSink(Gatherer<T, A, R> gatherer, Sink<R> sink)

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
beginback to summary
public void begin(long size)

Overrides default java.util.stream.Sink.begin.

Doc from java.util.stream.Sink.begin.

Resets the sink state to receive a fresh data set. This must be called before sending any data to the sink. After calling end(), you may call this method to reset the sink for another calculation.

Annotations
@Override
cancellationRequestedback to summary
public boolean cancellationRequested()

Overrides default java.util.stream.Sink.cancellationRequested.

Doc from java.util.stream.Sink.cancellationRequested.

Indicates that this Sink does not wish to receive any more data.

Annotations
@Override
cancellationRequestedback to summary
private boolean cancellationRequested(boolean knownProceed)
endback to summary
public void end()

Overrides default java.util.stream.Sink.end.

Doc from java.util.stream.Sink.end.

Indicates that all elements have been pushed. If the Sink is stateful, it should send any stored state downstream at this time, and should clear any accumulated state (and associated resources).

Prior to this call, the sink must be in the active state, and after this call it is returned to the initial state.

Annotations
@Override
isRejectingback to summary
public boolean isRejecting()

Overrides default java.util.stream.Gatherer.Downstream.isRejecting.

Doc from java.util.stream.Gatherer.Downstream.isRejecting.

Checks whether the next stage is known to not want any more elements sent to it.

Annotations
@Override
pushback to summary
public boolean push(R r)

Implements java.util.stream.Gatherer.Downstream.push.

Doc from java.util.stream.Gatherer.Downstream.push.

Pushes, if possible, the provided element downstream -- to the next stage in the pipeline.

Annotations
@Override
java.util.stream back to summary

pack-priv final Class GathererOp.NodeBuilder<X>

extends Object
implements Consumer<X>
Class Inheritance
All Implemented Interfaces
java.util.function.Consumer

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private Node<X>
private static final int
private GathererOp.NodeBuilder.Builder<X>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
accept(X x)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.

public Node<X>
private boolean
public GathererOp.NodeBuilder<X>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

leftMostback to summary
private Node<X> leftMost
LINEAR_APPEND_MAXback to summary
private static final int LINEAR_APPEND_MAX
rightMostback to summary
private GathererOp.NodeBuilder.Builder<X> rightMost

Constructor Detail

NodeBuilderback to summary
pack-priv NodeBuilder()

Method Detail

acceptback to summary
public void accept(X x)

Implements java.util.function.Consumer.accept.

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

Performs this operation on the given argument.

Annotations
@Override
buildback to summary
public Node<X> build()
isEmptyback to summary
private boolean isEmpty()
joinback to summary
public GathererOp.NodeBuilder<X> join(GathererOp.NodeBuilder<X> that)
java.util.stream back to summary

pack-priv final Class GathererOp.NodeBuilder.Builder<X>

extends SpinedBuffer<X>
implements Node<X>
Class Inheritance
All Implemented Interfaces
java.util.stream.Node

Field Summary

Inherited from java.util.stream.SpinedBuffer:
curChunkspine

Constructor Summary

AccessConstructor and Description
pack-priv

Constructor Detail

Builderback to summary
pack-priv Builder()