Top Description Fields Constructors Methods
java.util.stream

pack-priv abstract Class AbstractShortCircuitTask<P_IN, P_OUT, R, K extends AbstractShortCircuitTask<P_IN, P_OUT, R, K>>

extends AbstractTask<P_IN, P_OUT, R, K extends AbstractShortCircuitTask<P_IN, P_OUT, R, K>>
Class Inheritance
Known Direct Subclasses
java.util.stream.FindOps.FindTask, java.util.stream.MatchOps.MatchTask, java.util.stream.SliceOps.SliceTask, java.util.stream.WhileOps.TakeWhileTask
Annotations
@SuppressWarnings:serial
Type Parameters
<P_IN>
type of input elements to the pipeline
<P_OUT>
type of output elements from the pipeline
<R>
type of intermediate result, may be different from operation result type
<K>
type of child and sibling tasks
Imports
java.util.Spliterator, java.util.concurrent.atomic.AtomicReference

Abstract class for fork-join tasks used to implement short-circuiting stream ops, which can produce a result without processing all elements of the stream.
Since
1.8

Field Summary

Modifier and TypeField and Description
protected volatile boolean
canceled

Indicates whether this task has been canceled.

protected final AtomicReference<R>
sharedResult

The result for this computation; this is shared among all tasks and set exactly once

Inherited from java.util.stream.AbstractTask:
helperleftChildrightChildspliteratortargetSize

Constructor Summary

AccessConstructor and Description
protected
AbstractShortCircuitTask(PipelineHelper<P_OUT>
the PipelineHelper describing the stream pipeline up to this operation
helper
,
Spliterator<P_IN>
the Spliterator describing the source for this pipeline
spliterator
)

Constructor for root tasks.

protected
AbstractShortCircuitTask(K
parent task in the computation tree
parent
,
Spliterator<P_IN>
the Spliterator for the portion of the computation tree described by this task
spliterator
)

Constructor for non-root nodes.

Method Summary

Modifier and TypeMethod and Description
protected void
cancel()

Mark this task as canceled

protected void
cancelLaterNodes()

Cancels all tasks which succeed this one in the encounter order.

public void
compute()

Overrides java.util.stream.AbstractTask.compute.

Overrides AbstractTask version to include checks for early exits while splitting or computing.
protected abstract R

Returns:

the result to return when no task finds a result
getEmptyResult
()

Returns the value indicating the computation completed with no task finding a short-circuitable result.

public R
getLocalResult()

Overrides java.util.stream.AbstractTask.getLocalResult.

Retrieves the local result for this task.
public R
getRawResult()

Overrides java.util.stream.AbstractTask.getRawResult.

Retrieves the local result for this task
protected void
setLocalResult(R
The result to set for this task
localResult
)

Overrides java.util.stream.AbstractTask.setLocalResult.

Sets a local result for this task.
protected void
shortCircuit(R
the result found
result
)

Declares that a globally valid result has been found.

protected boolean

Returns:

true if this task or any parent is canceled.
taskCanceled
()

Queries whether this task is canceled.

Inherited from java.util.stream.AbstractTask:
doLeafgetLeafTargetgetParentgetTargetSizeisLeafisLeftmostNodeisRootmakeChildonCompletionsetRawResultsuggestTargetSize

Field Detail

canceledback to summary
protected volatile boolean canceled

Indicates whether this task has been canceled. Tasks may cancel other tasks in the computation under various conditions, such as in a find-first operation, a task that finds a value will cancel all tasks that are later in the encounter order.

sharedResultback to summary
protected final AtomicReference<R> sharedResult

The result for this computation; this is shared among all tasks and set exactly once

Constructor Detail

AbstractShortCircuitTaskback to summary
protected AbstractShortCircuitTask(PipelineHelper<P_OUT> helper, Spliterator<P_IN> spliterator)

Constructor for root tasks.

Parameters
helper:PipelineHelper<P_OUT>

the PipelineHelper describing the stream pipeline up to this operation

spliterator:Spliterator<P_IN>

the Spliterator describing the source for this pipeline

AbstractShortCircuitTaskback to summary
protected AbstractShortCircuitTask(K parent, Spliterator<P_IN> spliterator)

Constructor for non-root nodes.

Parameters
parent:K

parent task in the computation tree

spliterator:Spliterator<P_IN>

the Spliterator for the portion of the computation tree described by this task

Method Detail

cancelback to summary
protected void cancel()

Mark this task as canceled

cancelLaterNodesback to summary
protected void cancelLaterNodes()

Cancels all tasks which succeed this one in the encounter order. This includes canceling all the current task's right sibling, as well as the later right siblings of all its parents.

computeback to summary
public void compute()

Overrides java.util.stream.AbstractTask.compute.

Overrides AbstractTask version to include checks for early exits while splitting or computing.

Annotations
@Override
getEmptyResultback to summary
protected abstract R getEmptyResult()

Returns the value indicating the computation completed with no task finding a short-circuitable result. For example, for a "find" operation, this might be null or an empty Optional.

Returns:R

the result to return when no task finds a result

getLocalResultback to summary
public R getLocalResult()

Overrides java.util.stream.AbstractTask.getLocalResult.

Retrieves the local result for this task. If this task is the root, retrieves the shared result instead.

Returns:R

Doc from java.util.stream.AbstractTask.getLocalResult.

local result for this node previously stored with setLocalResult

Annotations
@Override
getRawResultback to summary
public R getRawResult()

Overrides java.util.stream.AbstractTask.getRawResult.

Retrieves the local result for this task

Returns:R

Doc from java.util.stream.AbstractTask.getRawResult.

local result for this node previously stored with setLocalResult

Annotations
@Override
setLocalResultback to summary
protected void setLocalResult(R localResult)

Overrides java.util.stream.AbstractTask.setLocalResult.

Sets a local result for this task. If this task is the root, set the shared result instead (if not already set).

Parameters
localResult:R

The result to set for this task

Annotations
@Override
shortCircuitback to summary
protected void shortCircuit(R result)

Declares that a globally valid result has been found. If another task has not already found the answer, the result is installed in sharedResult. The compute() method will check sharedResult before proceeding with computation, so this causes the computation to terminate early.

Parameters
result:R

the result found

taskCanceledback to summary
protected boolean taskCanceled()

Queries whether this task is canceled. A task is considered canceled if it or any of its parents have been canceled.

Returns:boolean

true if this task or any parent is canceled.