Class CompletableFutureUtils
- java.lang.Object
-
- com.commercetools.sync.commons.utils.CompletableFutureUtils
-
public final class CompletableFutureUtils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,S extends java.util.Collection<T>>
java.util.concurrent.CompletableFuture<S>collectionOfFuturesToFutureOfCollection(java.util.Collection<? extends java.util.concurrent.CompletionStage<T>> futures, java.util.stream.Collector<T,?,S> collector)Transforms a collection ofCompletionStageinto aCompletionStageof 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>>
java.util.concurrent.CompletableFuture<U>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>>
java.util.concurrent.CompletableFuture<U>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>>>
UmapValuesToFutures(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>>>
StoCompletableFutures(java.util.stream.Stream<java.util.concurrent.CompletionStage<T>> values, java.util.stream.Collector<java.util.concurrent.CompletableFuture<T>,?,S> collector)Converts a stream ofCompletionStageof values of type<T>into aCollectionof the type of the suppliedcollectorofCompletableFutureof values of type<T>.
-
-
-
Method Detail
-
mapValuesToFutureOfCompletedValues
@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)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. The type of the returned collection is decided by the supplied collector.- Type Parameters:
T- The type of the values.S- The type of the mapped completed values.U- The type of the collection returned in the future.- Parameters:
values- collection of values to apply a mapper function that would map each to aCompletionStage.mapper- function to map each value to aCompletionStagecollector- the collector to define the type of the collection returned.- Returns:
- a future containing a collection of completed stage results of the values after the mapper function was applied to each value in the supplied collection.
-
mapValuesToFutureOfCompletedValues
@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)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. The type of the collection is decided upon on by the supplied collector.- Type Parameters:
T- The type of the values.S- The type of the mapped completed values.- Parameters:
values- collection of values to apply a mapper function that would map each to aCompletionStage.mapper- function to map each value to aCompletionStage- Returns:
- a future containing a stream of completed stage results of the values after the mapper function was applied to each value in the supplied collection.
-
mapValuesToFutureOfCompletedValues
@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)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. The type of the returned collection is decided by the supplied collector.- Type Parameters:
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.- Parameters:
values- stream of values to apply a mapper function that would map each to aCompletionStage.mapper- function to map each value to aCompletionStagecollector- the collector to define the type of the collection returned.- Returns:
- a future containing a list of completed stage results of the values after the mapper function was applied to each one.
-
collectionOfFuturesToFutureOfCollection
@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)Transforms a collection ofCompletionStageinto aCompletionStageof 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.
- Type Parameters:
T- the element obtained from the set ofCompletionStageS- The type of the collection returned in the future.- Parameters:
futures- collection ofCompletionStagecollector- the collector to define the type of the collection returned.- Returns:
- the
CompletableFutureof a collection of elements
-
mapValuesToFutures
@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)Maps a stream of values to a future collection using the supplied mapper function. The type of the returned collection is decided by the supplied collector.- Type Parameters:
T- The type of the values.S- The type of the mapped values.U- The type of the collection returned.- Parameters:
values- stream of values to apply a mapper function that would map each to aCompletionStage.mapper- function to map each value to aCompletionStagecollector- the collector to define the type of the collection returned.- Returns:
- a collection of futures resulting from applying the mapper function on each value.
-
toCompletableFutures
@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)Converts a stream ofCompletionStageof values of type<T>into aCollectionof the type of the suppliedcollectorofCompletableFutureof 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.
- Type Parameters:
T- the type of the results of the stages.S- the concrete type of the collection returned.- Parameters:
values- stream ofCompletionStageof values of type<T>collector- the collector to define the type of the collection returned.- Returns:
- a
ListofCompletableFutureelements of type<T>.
-
-