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

pack-priv Interface Sink<T>

extends Consumer<T>
Known Direct Subinterfaces
java.util.stream.Sink.OfInt, java.util.stream.Sink.OfLong, java.util.stream.Sink.OfDouble, java.util.stream.TerminalSink, java.util.stream.WhileOps.DropWhileSink, java.util.stream.Node.Builder
Known Direct Implementers
java.util.stream.Sink.ChainedReference, java.util.stream.GathererOp.GatherSink, java.util.stream.MatchOps.BooleanTerminalSink, java.util.stream.Nodes.SizedCollectorTask, java.util.stream.Nodes.SizedCollectorTask.OfRef
Type Parameters
<T>
type of elements for value streams
Imports
java.util.Objects, java.util.function.Consumer, .DoubleConsumer, .IntConsumer, .LongConsumer

An extension of Consumer used to conduct values through the stages of a stream pipeline, with additional methods to manage size information, control flow, etc. Before calling the accept() method on a Sink for the first time, you must first call the begin() method to inform it that data is coming (optionally informing the sink how much data is coming), and after all data has been sent, you must call the end() method. After calling end(), you should not call accept() without again calling begin(). Sink also offers a mechanism by which the sink can cooperatively signal that it does not wish to receive any more data (the cancellationRequested() method), which a source can poll before sending more data to the Sink.

A sink may be in one of two states: an initial state and an active state. It starts out in the initial state; the begin() method transitions it to the active state, and the end() method transitions it back into the initial state, where it can be re-used. Data-accepting methods (such as accept() are only valid in the active state.

API Note

A stream pipeline consists of a source, zero or more intermediate stages (such as filtering or mapping), and a terminal stage, such as reduction or for-each. For concreteness, consider the pipeline:

int longestStringLengthStartingWithA
        = strings.stream()
                 .filter(s -> s.startsWith("A"))
                 .mapToInt(String::length)
                 .max();

Here, we have three stages, filtering, mapping, and reducing. The filtering stage consumes strings and emits a subset of those strings; the mapping stage consumes strings and emits ints; the reduction stage consumes those ints and computes the maximal value.

A Sink instance is used to represent each stage of this pipeline, whether the stage accepts objects, ints, longs, or doubles. Sink has entry points for accept(Object), accept(int), etc, so that we do not need a specialized interface for each primitive specialization. (It might be called a "kitchen sink" for this omnivorous tendency.) The entry point to the pipeline is the Sink for the filtering stage, which sends some elements "downstream" -- into the Sink for the mapping stage, which in turn sends integral values downstream into the Sink for the reduction stage. The Sink implementations associated with a given stage is expected to know the data type for the next stage, and call the correct accept method on its downstream Sink. Similarly, each stage must implement the correct accept method corresponding to the data type it accepts.

The specialized subtypes such as Sink.OfInt override accept(Object) to call the appropriate primitive specialization of accept, implement the appropriate primitive specialization of Consumer, and re-abstract the appropriate primitive specialization of accept.

The chaining subtypes such as ChainedInt not only implement Sink.OfInt, but also maintain a downstream field which represents the downstream Sink, and implement the methods begin(), end(), and cancellationRequested() to delegate to the downstream Sink. Most implementations of intermediate operations will use these chaining wrappers. For example, the mapping stage in the above example would look like:

IntSink is = new Sink.ChainedReference<U>(sink) {
        public void accept(U u) {
            downstream.accept(mapper.applyAsInt(u));
        }
    };

Here, we implement Sink.ChainedReference<U>, meaning that we expect to receive elements of type U as input, and pass the downstream sink to the constructor. Because the next stage expects to receive integers, we must call the accept(int) method when emitting values to the downstream. The accept() method applies the mapping function from U to int and passes the resulting value to the downstream Sink.

Since
1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
Sink.ChainedDouble<E_OUT>

Abstract Sink implementation designed for creating chains of sinks.

public abstract static class
Sink.ChainedInt<E_OUT>

Abstract Sink implementation designed for creating chains of sinks.

public abstract static class
Sink.ChainedLong<E_OUT>

Abstract Sink implementation designed for creating chains of sinks.

public abstract static class
Sink.ChainedReference<T, E_OUT>

Abstract Sink implementation for creating chains of sinks.

public static interface
Sink.OfDouble

Sink that implements Sink<Double>, re-abstracts accept(double), and wires accept(Double) to bridge to accept(double).

public static interface
Sink.OfInt

Sink that implements Sink<Integer>, re-abstracts accept(int), and wires accept(Integer) to bridge to accept(int).

public static interface
Sink.OfLong

Sink that implements Sink<Long>, re-abstracts accept(long), and wires accept(Long) to bridge to accept(long).

Method Summary

Modifier and TypeMethod and Description
public default void
accept(int value)

Implements java.util.function.Consumer.accept.

Accepts an int value.

public default void
accept(long value)

Implements java.util.function.Consumer.accept.

Accepts a long value.

public default void
accept(double value)

Implements java.util.function.Consumer.accept.

Accepts a double value.

public default void
begin(long
The exact size of the data to be pushed downstream, if known or -1 if unknown or infinite.

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

size
)

Resets the sink state to receive a fresh data set.

public default boolean

Returns:

true if cancellation is requested
cancellationRequested
()

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

public default void
end()

Indicates that all elements have been pushed.

Inherited from java.util.function.Consumer:
andThen

Method Detail

acceptback to summary
public default void accept(int value)

Implements java.util.function.Consumer.accept.

Accepts an int value.

Implementation Specification

The default implementation throws IllegalStateException.

Exceptions
IllegalStateException:
if this sink does not accept int values
acceptback to summary
public default void accept(long value)

Implements java.util.function.Consumer.accept.

Accepts a long value.

Implementation Specification

The default implementation throws IllegalStateException.

Exceptions
IllegalStateException:
if this sink does not accept long values
acceptback to summary
public default void accept(double value)

Implements java.util.function.Consumer.accept.

Accepts a double value.

Implementation Specification

The default implementation throws IllegalStateException.

Exceptions
IllegalStateException:
if this sink does not accept double values
beginback to summary
public default void begin(long size)

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.

Parameters
size:long

The exact size of the data to be pushed downstream, if known or -1 if unknown or infinite.

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

cancellationRequestedback to summary
public default boolean cancellationRequested()

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

Implementation Specification

The default implementation always returns false.

Returns:boolean

true if cancellation is requested

endback to summary
public default void 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.

java.util.stream back to summary

public abstract Class Sink.ChainedDouble<E_OUT>

extends Object
implements OfDouble
Class Inheritance
All Implemented Interfaces
java.util.stream.Sink.OfDouble, java.util.function.DoubleConsumer, java.util.stream.Sink, java.util.function.Consumer
Known Direct Subclasses
java.util.stream.SortedOps.AbstractDoubleSortingSink

Abstract Sink implementation designed for creating chains of sinks. The begin, end, and cancellationRequested methods are wired to chain to the downstream Sink. This implementation takes a downstream Sink of unknown input shape and produces a Sink.OfDouble. The implementation of the accept() method must call the correct accept() method on the downstream Sink.

Field Summary

Modifier and TypeField and Description
protected final Sink<? super E_OUT>

Constructor Summary

AccessConstructor and Description
public
ChainedDouble(Sink<? super E_OUT> downstream)

Method Summary

Modifier and TypeMethod and Description
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.

public void
end()

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

Indicates that all elements have been pushed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

downstreamback to summary
protected final Sink<? super E_OUT> downstream

Constructor Detail

ChainedDoubleback to summary
public ChainedDouble(Sink<? super E_OUT> downstream)

Method Detail

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
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
java.util.stream back to summary

public abstract Class Sink.ChainedInt<E_OUT>

extends Object
implements OfInt
Class Inheritance
All Implemented Interfaces
java.util.stream.Sink.OfInt, java.util.function.IntConsumer, java.util.stream.Sink, java.util.function.Consumer
Known Direct Subclasses
java.util.stream.SortedOps.AbstractIntSortingSink

Abstract Sink implementation designed for creating chains of sinks. The begin, end, and cancellationRequested methods are wired to chain to the downstream Sink. This implementation takes a downstream Sink of unknown input shape and produces a Sink.OfInt. The implementation of the accept() method must call the correct accept() method on the downstream Sink.

Field Summary

Modifier and TypeField and Description
protected final Sink<? super E_OUT>

Constructor Summary

AccessConstructor and Description
public
ChainedInt(Sink<? super E_OUT> downstream)

Method Summary

Modifier and TypeMethod and Description
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.

public void
end()

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

Indicates that all elements have been pushed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

downstreamback to summary
protected final Sink<? super E_OUT> downstream

Constructor Detail

ChainedIntback to summary
public ChainedInt(Sink<? super E_OUT> downstream)

Method Detail

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
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
java.util.stream back to summary

public abstract Class Sink.ChainedLong<E_OUT>

extends Object
implements OfLong
Class Inheritance
All Implemented Interfaces
java.util.stream.Sink.OfLong, java.util.function.LongConsumer, java.util.stream.Sink, java.util.function.Consumer
Known Direct Subclasses
java.util.stream.SortedOps.AbstractLongSortingSink

Abstract Sink implementation designed for creating chains of sinks. The begin, end, and cancellationRequested methods are wired to chain to the downstream Sink. This implementation takes a downstream Sink of unknown input shape and produces a Sink.OfLong. The implementation of the accept() method must call the correct accept() method on the downstream Sink.

Field Summary

Modifier and TypeField and Description
protected final Sink<? super E_OUT>

Constructor Summary

AccessConstructor and Description
public
ChainedLong(Sink<? super E_OUT> downstream)

Method Summary

Modifier and TypeMethod and Description
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.

public void
end()

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

Indicates that all elements have been pushed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

downstreamback to summary
protected final Sink<? super E_OUT> downstream

Constructor Detail

ChainedLongback to summary
public ChainedLong(Sink<? super E_OUT> downstream)

Method Detail

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
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
java.util.stream back to summary

public abstract Class Sink.ChainedReference<T, E_OUT>

extends Object
implements Sink<T>
Class Inheritance
All Implemented Interfaces
java.util.stream.Sink, java.util.function.Consumer
Known Direct Subclasses
java.util.stream.SortedOps.AbstractRefSortingSink

Abstract Sink implementation for creating chains of sinks. The begin, end, and cancellationRequested methods are wired to chain to the downstream Sink. This implementation takes a downstream Sink of unknown input shape and produces a Sink<T>. The implementation of the accept() method must call the correct accept() method on the downstream Sink.

Field Summary

Modifier and TypeField and Description
protected final Sink<? super E_OUT>

Constructor Summary

AccessConstructor and Description
public
ChainedReference(Sink<? super E_OUT> downstream)

Method Summary

Modifier and TypeMethod and Description
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.

public void
end()

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

Indicates that all elements have been pushed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

downstreamback to summary
protected final Sink<? super E_OUT> downstream

Constructor Detail

ChainedReferenceback to summary
public ChainedReference(Sink<? super E_OUT> downstream)

Method Detail

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
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
java.util.stream back to summary

public Interface Sink.OfDouble

extends Sink<Double>, DoubleConsumer
Known Direct Subinterfaces
java.util.stream.Node.Builder.OfDouble
Known Direct Implementers
java.util.stream.Sink.ChainedDouble, java.util.stream.FindOps.FindSink.OfDouble, java.util.stream.ForEachOps.ForEachOp.OfDouble, java.util.stream.Nodes.SizedCollectorTask.OfDouble, java.util.stream.ReduceOps.CountingSink.OfDouble
Annotations
@SuppressWarnings:overloads

Sink that implements Sink<Double>, re-abstracts accept(double), and wires accept(Double) to bridge to accept(double).

Method Summary

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

Redeclares java.util.function.DoubleConsumer.accept.

Redeclares as abstract: java.util.stream.Sink.accept.

Accepts a double value.

public default void
accept(Double i)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.

Inherited from java.util.function.DoubleConsumer:
andThen
Inherited from java.util.stream.Sink:
acceptacceptbegincancellationRequestedend

Method Detail

acceptback to summary
public void accept(double value)

Redeclares java.util.function.DoubleConsumer.accept.

Redeclares as abstract: java.util.stream.Sink.accept.

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

Accepts a double value.

Annotations
@Override
acceptback to summary
public default void accept(Double i)

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

public Interface Sink.OfInt

extends Sink<Integer>, IntConsumer
Known Direct Subinterfaces
java.util.stream.Node.Builder.OfInt
Known Direct Implementers
java.util.stream.Sink.ChainedInt, java.util.stream.FindOps.FindSink.OfInt, java.util.stream.ForEachOps.ForEachOp.OfInt, java.util.stream.Nodes.SizedCollectorTask.OfInt, java.util.stream.ReduceOps.CountingSink.OfInt
Annotations
@SuppressWarnings:overloads

Sink that implements Sink<Integer>, re-abstracts accept(int), and wires accept(Integer) to bridge to accept(int).

Method Summary

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

Redeclares java.util.function.IntConsumer.accept.

Redeclares as abstract: java.util.stream.Sink.accept.

Accepts an int value.

public default void
accept(Integer i)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.

Inherited from java.util.function.IntConsumer:
andThen
Inherited from java.util.stream.Sink:
acceptacceptbegincancellationRequestedend

Method Detail

acceptback to summary
public void accept(int value)

Redeclares java.util.function.IntConsumer.accept.

Redeclares as abstract: java.util.stream.Sink.accept.

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

Accepts an int value.

Annotations
@Override
acceptback to summary
public default void accept(Integer i)

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

public Interface Sink.OfLong

extends Sink<Long>, LongConsumer
Known Direct Subinterfaces
java.util.stream.Node.Builder.OfLong
Known Direct Implementers
java.util.stream.Sink.ChainedLong, java.util.stream.FindOps.FindSink.OfLong, java.util.stream.ForEachOps.ForEachOp.OfLong, java.util.stream.Nodes.SizedCollectorTask.OfLong, java.util.stream.ReduceOps.CountingSink.OfLong
Annotations
@SuppressWarnings:overloads

Sink that implements Sink<Long>, re-abstracts accept(long), and wires accept(Long) to bridge to accept(long).

Method Summary

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

Redeclares java.util.function.LongConsumer.accept.

Redeclares as abstract: java.util.stream.Sink.accept.

Accepts a long value.

public default void
accept(Long i)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.

Inherited from java.util.function.LongConsumer:
andThen
Inherited from java.util.stream.Sink:
acceptacceptbegincancellationRequestedend

Method Detail

acceptback to summary
public void accept(long value)

Redeclares java.util.function.LongConsumer.accept.

Redeclares as abstract: java.util.stream.Sink.accept.

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

Accepts a long value.

Annotations
@Override
acceptback to summary
public default void accept(Long i)

Implements java.util.function.Consumer.accept.

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

Performs this operation on the given argument.

Annotations
@Override