public class Combinators extends Object
|Modifier and Type||Method||Description|
Given a collection of stages, returns a new
Given a collection of stages all of the same type, returns a new
Applies a collector to the results of all
public static CompletionStage<Void> allOf(Collection<? extends CompletionStage<?>> stages)
CompletionStagethat is completed when all input stages are complete. If any stage completes exceptionally, the returned stage will complete exceptionally.
public static <T> CompletionStage<Collection<T>> collect(Collection<? extends CompletionStage<T>> stages)
CompletionStagethat is completed with a collection of the results of all input stages when all stages complete. If the input collection has a defined order, the order will be preserved in the returned collection. If an element of
stagescompletes exceptionally, so too will the CompletionStage returned by this method.
public static <T,A,R> CompletionStage<R> collect(Collection<? extends CompletionStage<T>> stages, Collector<? super T,A,R> collector)
stagesafter all complete, returning a
CompletionStageof the collected result. There is no need nor benefit for the Collector to have the
CONCURRENT characteristic, the
collectorwill be applied in a single thread. If any of the input stages completes exceptionally, so too will the CompletionStage returned by this method.
T- The type of the elements in
stageswhich will be collected by
A- The intermediate collection type
R- The final type returned by
stages- a Collection of stages all of type T
Collectorwhich will be applied to the results of
stagesto produce the final R result.
CompletionStagewhich will complete with the R typed object that is produced by
collectorwhen all input
stagesor any of its elements are null
public static <K,V> CompletionStage<Map<K,V>> keyedAll(Map<K,? extends CompletionStage<V>> stageMap)
CompletionStagesof values, returns a
CompletionStagewhich completes with a
Map<K, V>when all the CompletionStages in the input map have completed. For example, if we have an asynchronous method to lookup student grade point averages.
If a value in
Map<Student, CompletionStage<Double>> gpaFutures = students .stream() .collect(Collectors.toMap(Functions.identity(), student -> getGpaAsync(student)); Map<Student, Double> studentGpas = keyedAll(gpaFutures).toCompletableFuture().join();
stageMapcompletes exceptionally, so too will the CompletionStage returned by this method.
K- the input and output key type
V- the value type for the map that will be produced by the returned
stageMap- a Map with keys of type K and
CompletionStagesof type V for values
CompletionStagethat will be completed with a map mapping keys of type K to the values returned by the CompletionStages in
stageMapor any of its values are null
Copyright © 2018. All rights reserved.