T - The type of the elements that the publisher emits.public final class PublisherBuilder<T> extends Object
Publisher.ReactiveStreams| Modifier and Type | Method and Description |
|---|---|
org.reactivestreams.Publisher<T> |
buildRs()
Build this stream, using the first
ReactiveStreamsEngine found by the ServiceLoader. |
org.reactivestreams.Publisher<T> |
buildRs(ReactiveStreamsEngine engine)
Build this stream, using the supplied
ReactiveStreamsEngine. |
CompletionRunner<Void> |
cancel()
Cancels the stream as soon as it starts.
|
<R,A> CompletionRunner<R> |
collect(Collector<? super T,A,R> collector)
Collect the elements emitted by this publisher builder using the given
Collector. |
<R> CompletionRunner<R> |
collect(Supplier<R> supplier,
BiConsumer<R,? super T> accumulator)
Collect the elements emitted by this processor builder using a
Collector built from the given
supplier and accumulator. |
PublisherBuilder<T> |
distinct()
Creates a stream consisting of the distinct elements (according to
Object.equals(Object)) of this stream. |
PublisherBuilder<T> |
dropWhile(Predicate<? super T> predicate)
Drop the longest prefix of elements from this stream that satisfy the given
predicate. |
PublisherBuilder<T> |
filter(Predicate<? super T> predicate)
Filter elements emitted by this publisher using the given
Predicate. |
CompletionRunner<Optional<T>> |
findFirst()
Find the first element emitted by the
Publisher, and return it in a
CompletionStage. |
<S> PublisherBuilder<S> |
flatMap(Function<? super T,PublisherBuilder<? extends S>> mapper)
Map the elements to publishers, and flatten so that the elements emitted by publishers produced by the
mapper function are emitted from this stream. |
<S> PublisherBuilder<S> |
flatMapCompletionStage(Function<? super T,? extends CompletionStage<? extends S>> mapper)
Map the elements to
CompletionStage, and flatten so that the elements the values redeemed by each
CompletionStage are emitted from this publisher. |
<S> PublisherBuilder<S> |
flatMapIterable(Function<? super T,? extends Iterable<? extends S>> mapper)
Map the elements to
Iterable's, and flatten so that the elements contained in each iterable are
emitted by this stream. |
<S> PublisherBuilder<S> |
flatMapPublisher(Function<? super T,org.reactivestreams.Publisher<? extends S>> mapper)
Map the elements to publishers, and flatten so that the elements emitted by publishers produced by the
mapper function are emitted from this stream. |
CompletionRunner<Void> |
forEach(Consumer<? super T> action)
Performs an action for each element on this stream.
|
CompletionRunner<Void> |
ignore()
Ignores each element of this stream.
|
PublisherBuilder<T> |
limit(long maxSize)
Truncate this stream, ensuring the stream is no longer than
maxSize elements in length. |
<R> PublisherBuilder<R> |
map(Function<? super T,? extends R> mapper)
Map the elements emitted by this publisher using the
mapper function. |
PublisherBuilder<T> |
onComplete(Runnable action)
Returns a stream containing all the elements from this stream, additionally performing the provided action when this
stream completes.
|
PublisherBuilder<T> |
onError(Consumer<Throwable> errorHandler)
Returns a stream containing all the elements from this stream, additionally performing the provided action if this
stream conveys an error.
|
PublisherBuilder<T> |
onErrorResume(Function<Throwable,T> errorHandler)
Returns a stream containing all the elements from this stream.
|
PublisherBuilder<T> |
onErrorResumeWith(Function<Throwable,PublisherBuilder<T>> errorHandler)
Returns a stream containing all the elements from this stream.
|
<S> PublisherBuilder<S> |
onErrorResumeWithPublisher(Function<Throwable,org.reactivestreams.Publisher<? extends S>> errorHandler)
Returns a stream containing all the elements from this stream.
|
PublisherBuilder<T> |
onTerminate(Runnable action)
Returns a stream containing all the elements from this stream, additionally performing the provided action when this
stream completes or failed.
|
PublisherBuilder<T> |
peek(Consumer<? super T> consumer)
Returns a stream containing all the elements from this stream, additionally performing the provided action on each
element.
|
CompletionRunner<Optional<T>> |
reduce(BinaryOperator<T> accumulator)
Perform a reduction on the elements of this stream, using provided the accumulation function.
|
CompletionRunner<T> |
reduce(T identity,
BinaryOperator<T> accumulator)
Perform a reduction on the elements of this stream, using the provided identity value and the accumulation
function.
|
PublisherBuilder<T> |
skip(long n)
Discard the first
n of this stream. |
PublisherBuilder<T> |
takeWhile(Predicate<? super T> predicate)
Take the longest prefix of elements from this stream that satisfy the given
predicate. |
CompletionRunner<Void> |
to(org.reactivestreams.Subscriber<T> subscriber)
Connect the outlet of the
Publisher built by this builder to the given Subscriber. |
<R> CompletionRunner<R> |
to(SubscriberBuilder<T,R> subscriber)
Connect the outlet of this publisher builder to the given
SubscriberBuilder graph. |
CompletionRunner<List<T>> |
toList()
Collect the elements emitted by this publisher builder into a
List |
<R> PublisherBuilder<R> |
via(org.reactivestreams.Processor<T,R> processor)
Connect the outlet of this publisher builder to the given
ProcessorBuilder graph. |
<R> PublisherBuilder<R> |
via(ProcessorBuilder<T,R> processor)
Connect the outlet of the
Publisher built by this builder to the given Processor. |
public <R> PublisherBuilder<R> map(Function<? super T,? extends R> mapper)
mapper function.R - The type of elements that the mapper function emits.mapper - The function to use to map the elements.public PublisherBuilder<T> peek(Consumer<? super T> consumer)
consumer - The function called for every element.T and emits the same elements. In between,
the given function is called for each element.public PublisherBuilder<T> filter(Predicate<? super T> predicate)
Predicate.
Any elements that return true when passed to the Predicate will be emitted, all other
elements will be dropped.
predicate - The predicate to apply to each element.public PublisherBuilder<T> distinct()
Object.equals(Object)) of this stream.public <S> PublisherBuilder<S> flatMap(Function<? super T,PublisherBuilder<? extends S>> mapper)
mapper function are emitted from this stream.
This method operates on one publisher at a time. The result is a concatenation of elements emitted from all the publishers produced by the mapper function.
Unlike flatMapPublisher(Function)}, the mapper function returns a PublisherBuilder instead of a
Publisher.
S - The type of the elements emitted from the new publisher.mapper - The mapper function.public <S> PublisherBuilder<S> flatMapPublisher(Function<? super T,org.reactivestreams.Publisher<? extends S>> mapper)
mapper function are emitted from this stream.
This method operates on one publisher at a time. The result is a concatenation of elements emitted from all the publishers produced by the mapper function.
Unlike flatMap(Function), the mapper function returns a Publisher instead of a
PublisherBuilder.
S - The type of the elements emitted from the new publisher.mapper - The mapper function.public <S> PublisherBuilder<S> flatMapCompletionStage(Function<? super T,? extends CompletionStage<? extends S>> mapper)
CompletionStage, and flatten so that the elements the values redeemed by each
CompletionStage are emitted from this publisher.
This method only works with one element at a time. When an element is received, the mapper function is
executed, and the next element is not consumed or passed to the mapper function until the previous
CompletionStage is redeemed. Hence this method also guarantees that ordering of the stream is maintained.
S - The type of the elements emitted from the new publisher.mapper - The mapper function.public <S> PublisherBuilder<S> flatMapIterable(Function<? super T,? extends Iterable<? extends S>> mapper)
Iterable's, and flatten so that the elements contained in each iterable are
emitted by this stream.
This method operates on one iterable at a time. The result is a concatenation of elements contain in all the
iterables returned by the mapper function.
S - The type of the elements emitted from the new publisher.mapper - The mapper function.public PublisherBuilder<T> limit(long maxSize)
maxSize elements in length.
If maxSize is reached, the stream will be completed, and upstream will be cancelled. Completion of the
stream will occur immediately when the element that satisfies the maxSize is received.
maxSize - The maximum size of the returned stream.IllegalArgumentException - If maxSize is less than zero.public PublisherBuilder<T> skip(long n)
n of this stream. If this stream contains fewer than n elements, this stream will
effectively be an empty stream.n - The number of elements to discard.IllegalArgumentException - If n is less than zero.public PublisherBuilder<T> takeWhile(Predicate<? super T> predicate)
predicate.
When the predicate returns false, the stream will be completed, and upstream will be cancelled.
predicate - The predicate.public PublisherBuilder<T> dropWhile(Predicate<? super T> predicate)
predicate.
As long as the predicate returns true, no elements will be emitted from this stream. Once the first element
is encountered for which the predicate returns false, all subsequent elements will be emitted, and the
predicate will no longer be invoked.
predicate - The predicate.public CompletionRunner<Void> forEach(Consumer<? super T> action)
The returned CompletionStage will be redeemed when the stream completes, either successfully if the stream
completes normally, or with an error if the stream completes with an error or if the action throws an exception.
action - The action.public CompletionRunner<Void> ignore()
The returned CompletionStage will be redeemed when the stream completes, either successfully if the
stream completes normally, or with an error if the stream completes with an error or if the action throws an
exception.
public CompletionRunner<Void> cancel()
The returned CompletionStage will be immediately redeemed as soon as the stream starts.
public CompletionRunner<T> reduce(T identity, BinaryOperator<T> accumulator)
The result of the reduction is returned in the CompletionStage.
identity - The identity value.accumulator - The accumulator function.public CompletionRunner<Optional<T>> reduce(BinaryOperator<T> accumulator)
The result of the reduction is returned in the CompletionStage. If there are no elements in this stream,
empty will be returned.
accumulator - The accumulator function.public CompletionRunner<Optional<T>> findFirst()
Publisher, and return it in a
CompletionStage.
If the stream is completed before a single element is emitted, then Optional.empty() will be emitted.
CompletionRunner that emits the element when found.public <R,A> CompletionRunner<R> collect(Collector<? super T,A,R> collector)
Collector.
Since Reactive Streams are intrinsically sequential, only the accumulator of the collector will be used, the combiner will not be used.
R - The result of the collector.A - The accumulator type.collector - The collector to collect the elements.CompletionRunner that emits the collected result.public <R> CompletionRunner<R> collect(Supplier<R> supplier, BiConsumer<R,? super T> accumulator)
Collector built from the given
supplier and accumulator.
Since Reactive Streams are intrinsically sequential, the combiner will not be used. This is why this method does not accept a combiner method.
R - The result of the collector.supplier - a function that creates a new result container. It creates objects of type <A>.accumulator - an associative, non-interfering, stateless function for incorporating an additional element into a
resultCompletionRunner that emits the collected result.public CompletionRunner<List<T>> toList()
ListCompletionRunner that emits the list.public CompletionRunner<Void> to(org.reactivestreams.Subscriber<T> subscriber)
Publisher built by this builder to the given Subscriber.subscriber - The subscriber to connect.CompletionRunner that completes when the stream completes.public <R> CompletionRunner<R> to(SubscriberBuilder<T,R> subscriber)
SubscriberBuilder graph.subscriber - The subscriber builder to connect.CompletionRunner that completes when the stream completes.public <R> PublisherBuilder<R> via(ProcessorBuilder<T,R> processor)
Publisher built by this builder to the given Processor.processor - The processor to connect.PublisherBuilder that represents the passed in processors outlet.public <R> PublisherBuilder<R> via(org.reactivestreams.Processor<T,R> processor)
ProcessorBuilder graph.processor - The processor builder to connect.PublisherBuilder that represents the passed in processor builders outlet.public PublisherBuilder<T> onError(Consumer<Throwable> errorHandler)
errorHandler - The function called with the failure.T and emits the same elements. If the
stream conveys a failure, the given error handler is called.public PublisherBuilder<T> onErrorResume(Function<Throwable,T> errorHandler)
onError(Consumer), it invokes the given method and emits the result as final event of the stream.
By default, when a stream encounters an error that prevents it from emitting the expected item to its subscriber,
the stream (publisher) invokes its subscriber's onError method, and then terminate without invoking
any more of its subscriber's methods. This operator changes this behavior. If the current stream encounters an
error, instead of invoking its subscriber's onError method, it will instead emit the return value of
the passed function. This operator prevents errors from propagating or to supply fallback data should errors be
encountered.errorHandler - the function returning the value that need to be emitting instead of the error.
The function must not return nullpublic PublisherBuilder<T> onErrorResumeWith(Function<Throwable,PublisherBuilder<T>> errorHandler)
onError(Consumer), it invokes the given method and emits the returned PublisherBuilder
instead.
By default, when a stream encounters an error that prevents it from emitting the expected item to its subscriber,
the stream (publisher) invokes its subscriber's onError method, and then terminate without invoking
any more of its subscriber's methods. This operator changes this behavior. If the current stream encounters an
error, instead of invoking its subscriber's onError method, it will instead relinquish control to the
PublisherBuilder returned from given function, which invoke the subscriber's onNext method if
it is able to do so. In such a case, because no publisher necessarily invokes onError, the subscriber
may never know that an error happened.errorHandler - the function returning the stream that need to be emitting instead of the error.
The function must not return nullpublic <S> PublisherBuilder<S> onErrorResumeWithPublisher(Function<Throwable,org.reactivestreams.Publisher<? extends S>> errorHandler)
onError(Consumer), it invokes the given method and emits the returned PublisherBuilder
instead.
By default, when a stream encounters an error that prevents it from emitting the expected item to its subscriber,
the stream (publisher) invokes its subscriber's onError method, and then terminate without invoking
any more of its subscriber's methods. This operator changes this behavior. If the current stream encounters an
error, instead of invoking its subscriber's onError method, it will instead relinquish control to the
PublisherBuilder returned from given function, which invoke the subscriber's onNext method if
it is able to do so. In such a case, because no publisher necessarily invokes onError, the subscriber
may never know that an error happened.errorHandler - the function returning the stream that need to be emitting instead of the error.
The function must not return nullpublic PublisherBuilder<T> onTerminate(Runnable action)
onError(Consumer) and onComplete(Runnable). In addition, the action is called if
the stream is cancelled downstream.action - The function called when the stream completes or failed.T and emits the same elements. The given
action is called when the stream completes or fails.public PublisherBuilder<T> onComplete(Runnable action)
action - The function called when the stream completes.T and emits the same elements. The given
action is called when the stream completes.public org.reactivestreams.Publisher<T> buildRs()
ReactiveStreamsEngine found by the ServiceLoader.Processor that will run this stream.public org.reactivestreams.Publisher<T> buildRs(ReactiveStreamsEngine engine)
ReactiveStreamsEngine.engine - The engine to run the stream with.Publisher that will run this stream.Copyright © 2018 Eclipse Foundation. All rights reserved.