public final class CompletableFutureUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T,S extends java.util.Collection<T>> |
collectionOfFuturesToFutureOfCollection(java.util.Collection<? extends java.util.concurrent.CompletionStage<T>> futures,
java.util.stream.Collector<T,?,S> collector)
Transforms a collection of
CompletionStage into a CompletionStage of a
collection, that will be completed once all the elements of the given futures are completed. |
static <T,S> java.util.concurrent.CompletableFuture<java.util.stream.Stream<S>> |
mapValuesToFutureOfCompletedValues(java.util.Collection<T> values,
java.util.function.Function<T,java.util.concurrent.CompletionStage<S>> mapper)
Creates a Future containing a stream of value results after the mapper function is applied to
each value in the supplied collection and completed it.
|
static <T,S,U extends java.util.Collection<S>> |
mapValuesToFutureOfCompletedValues(java.util.Collection<T> values,
java.util.function.Function<T,java.util.concurrent.CompletionStage<S>> mapper,
java.util.stream.Collector<S,?,U> collector)
Creates a Future containing a collection of value results after the mapper function is applied
to each value in the supplied collection and completed it.
|
static <T,S,U extends java.util.Collection<S>> |
mapValuesToFutureOfCompletedValues(java.util.stream.Stream<T> values,
java.util.function.Function<T,java.util.concurrent.CompletionStage<S>> mapper,
java.util.stream.Collector<S,?,U> collector)
Creates a Future containing a collection of value results after the mapper function is applied
to each value in the supplied stream and completed it.
|
static <T,S,U extends java.util.Collection<java.util.concurrent.CompletableFuture<S>>> |
mapValuesToFutures(java.util.stream.Stream<T> values,
java.util.function.Function<T,java.util.concurrent.CompletionStage<S>> mapper,
java.util.stream.Collector<java.util.concurrent.CompletableFuture<S>,?,U> collector)
Maps a stream of values to a future collection using the supplied mapper function.
|
static <T,S extends java.util.Collection<java.util.concurrent.CompletableFuture<T>>> |
toCompletableFutures(java.util.stream.Stream<java.util.concurrent.CompletionStage<T>> values,
java.util.stream.Collector<java.util.concurrent.CompletableFuture<T>,?,S> collector)
Converts a stream of
CompletionStage of values of type <T> into a Collection of the type of the supplied collector of CompletableFuture of
values of type <T> . |
@Nonnull public static <T,S,U extends java.util.Collection<S>> java.util.concurrent.CompletableFuture<U> mapValuesToFutureOfCompletedValues(@Nonnull java.util.Collection<T> values, @Nonnull java.util.function.Function<T,java.util.concurrent.CompletionStage<S>> mapper, @Nonnull java.util.stream.Collector<S,?,U> collector)
T
- The type of the values.S
- The type of the mapped completed values.U
- The type of the collection returned in the future.values
- collection of values to apply a mapper function that would map each to a CompletionStage
.mapper
- function to map each value to a CompletionStage
collector
- the collector to define the type of the collection returned.@Nonnull public static <T,S> java.util.concurrent.CompletableFuture<java.util.stream.Stream<S>> mapValuesToFutureOfCompletedValues(@Nonnull java.util.Collection<T> values, @Nonnull java.util.function.Function<T,java.util.concurrent.CompletionStage<S>> mapper)
T
- The type of the values.S
- The type of the mapped completed values.values
- collection of values to apply a mapper function that would map each to a CompletionStage
.mapper
- function to map each value to a CompletionStage
@Nonnull public static <T,S,U extends java.util.Collection<S>> java.util.concurrent.CompletableFuture<U> mapValuesToFutureOfCompletedValues(@Nonnull java.util.stream.Stream<T> values, @Nonnull java.util.function.Function<T,java.util.concurrent.CompletionStage<S>> mapper, @Nonnull java.util.stream.Collector<S,?,U> collector)
T
- The type of the values.S
- The type of the mapping of the values.U
- The type of the collection returned in the future.values
- stream of values to apply a mapper function that would map each to a CompletionStage
.mapper
- function to map each value to a CompletionStage
collector
- the collector to define the type of the collection returned.@Nonnull public static <T,S extends java.util.Collection<T>> java.util.concurrent.CompletableFuture<S> collectionOfFuturesToFutureOfCollection(@Nonnull java.util.Collection<? extends java.util.concurrent.CompletionStage<T>> futures, @Nonnull java.util.stream.Collector<T,?,S> collector)
CompletionStage
into a CompletionStage
of a
collection, that will be completed once all the elements of the given futures are completed. In
case multiple stages end exceptionally only one error is kept. The type of the returned
collection is decided by the supplied collector.
Note: Null futures in the collection are filtered out.
T
- the element obtained from the set of CompletionStage
S
- The type of the collection returned in the future.futures
- collection of CompletionStage
collector
- the collector to define the type of the collection returned.CompletableFuture
of a collection of elements@Nonnull public static <T,S,U extends java.util.Collection<java.util.concurrent.CompletableFuture<S>>> U mapValuesToFutures(@Nonnull java.util.stream.Stream<T> values, @Nonnull java.util.function.Function<T,java.util.concurrent.CompletionStage<S>> mapper, @Nonnull java.util.stream.Collector<java.util.concurrent.CompletableFuture<S>,?,U> collector)
T
- The type of the values.S
- The type of the mapped values.U
- The type of the collection returned.values
- stream of values to apply a mapper function that would map each to a CompletionStage
.mapper
- function to map each value to a CompletionStage
collector
- the collector to define the type of the collection returned.@Nonnull public static <T,S extends java.util.Collection<java.util.concurrent.CompletableFuture<T>>> S toCompletableFutures(@Nonnull java.util.stream.Stream<java.util.concurrent.CompletionStage<T>> values, @Nonnull java.util.stream.Collector<java.util.concurrent.CompletableFuture<T>,?,S> collector)
CompletionStage
of values of type <T>
into a Collection
of the type of the supplied collector
of CompletableFuture
of
values of type <T>
. The type of the returned collection is decided by the supplied
collector.
Note: Null futures in the stream are filtered out.
T
- the type of the results of the stages.S
- the concrete type of the collection returned.values
- stream of CompletionStage
of values of type <T>
collector
- the collector to define the type of the collection returned.List
of CompletableFuture
elements of type <T>
.