/** * Returns a {@code Spliterator} describing a parallel evaluation of the * operation, using the specified {@code 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. * * <p><b>Implementation Requirements:</b><br> The default implementation behaves as if: * <pre>{@code * return evaluateParallel(helper, i -> (E_OUT[]) new * Object[i]).spliterator(); * }</pre> * and is suitable for implementations that cannot do better than a full * synchronous evaluation. * * @param helper the pipeline helper * @param spliterator the source {@code Spliterator} * @return a {@code Spliterator} describing the result of the evaluation */ @SuppressWarnings("unchecked") <P_IN> Spliterator<E_OUT> opEvaluateParallelLazy(PipelineHelper<E_OUT> helper, Spliterator<P_IN> spliterator) { return opEvaluateParallel(helper, spliterator, i -> (E_OUT[]) new Object[i]).spliterator(); } }
/** * Returns a {@code Spliterator} describing a parallel evaluation of the * operation, using the specified {@code 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. * * <p><b>Implementation Requirements:</b><br> The default implementation behaves as if: * <pre>{@code * return evaluateParallel(helper, i -> (E_OUT[]) new * Object[i]).spliterator(); * }</pre> * and is suitable for implementations that cannot do better than a full * synchronous evaluation. * * @param helper the pipeline helper * @param spliterator the source {@code Spliterator} * @return a {@code Spliterator} describing the result of the evaluation */ @SuppressWarnings("unchecked") <P_IN> Spliterator<E_OUT> opEvaluateParallelLazy(PipelineHelper<E_OUT> helper, Spliterator<P_IN> spliterator) { return opEvaluateParallel(helper, spliterator, i -> (E_OUT[]) new Object[i]).spliterator(); } }
/** * Collect the elements output from the pipeline stage. * * @param generator the array generator to be used to create array instances * @return a flat array-backed Node that holds the collected output elements */ @SuppressWarnings("unchecked") final Node<E_OUT> evaluateToArrayNode(IntFunction<E_OUT[]> generator) { if (linkedOrConsumed) { throw new IllegalStateException(MSG_STREAM_LINKED); } linkedOrConsumed = true; // If the last intermediate operation is stateful then // evaluate directly to avoid an extra collection step if (isParallel() && previousStage != null && opIsStateful()) { // Set the depth of this, last, pipeline stage to zero to slice the // pipeline such that this operation will not be included in the // upstream slice and upstream operations will not be included // in this slice depth = 0; return opEvaluateParallel(previousStage, previousStage.sourceSpliterator(0), generator); } else { return evaluate(sourceSpliterator(0), true, generator); } }
/** * Collect the elements output from the pipeline stage. * * @param generator the array generator to be used to create array instances * @return a flat array-backed Node that holds the collected output elements */ @SuppressWarnings("unchecked") final Node<E_OUT> evaluateToArrayNode(IntFunction<E_OUT[]> generator) { if (linkedOrConsumed) { throw new IllegalStateException(MSG_STREAM_LINKED); } linkedOrConsumed = true; // If the last intermediate operation is stateful then // evaluate directly to avoid an extra collection step if (isParallel() && previousStage != null && opIsStateful()) { // Set the depth of this, last, pipeline stage to zero to slice the // pipeline such that this operation will not be included in the // upstream slice and upstream operations will not be included // in this slice depth = 0; return opEvaluateParallel(previousStage, previousStage.sourceSpliterator(0), generator); } else { return evaluate(sourceSpliterator(0), true, generator); } }