From 61374f088028d1a6062552952a6450c1dec03ea2 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 27 Apr 2024 21:45:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20change=20parameter=20type=20to=20`C?= =?UTF-8?q?ompletionStage`=20and=20use=20covariance=20for=20methods=20`all?= =?UTF-8?q?Of*/anyOf*/allTupleOf*`=20=F0=9F=A7=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/foldright/cffu/Cffu.java | 252 ++------ .../java/io/foldright/cffu/CffuFactory.java | 574 +++--------------- .../cffu/CompletableFutureUtils.java | 136 +++-- .../cffu/NoCfsProvidedException.java | 6 +- .../kotlin/CompletableFutureExtensions.kt | 62 +- 5 files changed, 247 insertions(+), 783 deletions(-) diff --git a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java index 7893eedc..1f7a826e 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java +++ b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java @@ -567,34 +567,12 @@ public Cffu thenCombineFastFailAsync(CompletionStage othe //# convenient `allTupleOf` methods: // providing these method is convenient for method chaining // - // - allTupleOf(Cffu...) - // - allTupleOf(CompletableFuture...) - // - allTupleOfFastFail(Cffu...) - // - allTupleOfFastFail(CompletableFuture...) + // - allTupleOf(CompletionStage...) + // - allTupleOfFastFail(CompletionStage...) //////////////////////////////////////////////////////////////////////////////// /** - * This method is the same as {@link CffuFactory#allTupleOf(Cffu, Cffu)}, - * providing this method is convenient for method chaining. - *

- * Calling this method - *

- * {@code allTuple = cffu.allTupleOf(cffu2);} - *

- * is the same as: - *

- * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu, cffu2);} - * - * @return the new Cffu - * @see CffuFactory#allTupleOf(Cffu, Cffu) - */ - @Contract(pure = true) - public Cffu> allTupleOf(Cffu cf2) { - return fac.allTupleOf(this, cf2); - } - - /** - * This method is the same as {@link CffuFactory#allTupleOf(CompletableFuture, CompletableFuture)}, + * This method is the same as {@link CffuFactory#allTupleOf(CompletionStage, CompletionStage)}, * providing this method is convenient for method chaining. *

* Calling this method @@ -603,38 +581,18 @@ public Cffu> allTupleOf(Cffu cf2) { *

* is the same as: *

- * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu.toCompletableFuture(), cf2);} + * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu, cf2);} * * @return the new Cffu - * @see CffuFactory#allTupleOf(CompletableFuture, CompletableFuture) + * @see CffuFactory#allTupleOf(CompletionStage, CompletionStage) */ @Contract(pure = true) - public Cffu> allTupleOf(CompletableFuture cf2) { - return fac.allTupleOf(toCompletableFuture(), cf2); + public Cffu> allTupleOf(CompletionStage cf2) { + return fac.allTupleOf(cf, cf2); } /** - * This method is the same as {@link CffuFactory#allTupleOfFastFail(Cffu, Cffu)}, - * providing this method is convenient for method chaining. - *

- * Calling this method - *

- * {@code allTuple = cffu.allTupleOfFastFail(cffu2);} - *

- * is the same as: - *

- * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cffu2);} - * - * @return the new Cffu - * @see CffuFactory#allTupleOfFastFail(Cffu, Cffu) - */ - @Contract(pure = true) - public Cffu> allTupleOfFastFail(Cffu cf2) { - return fac.allTupleOfFastFail(this, cf2); - } - - /** - * This method is the same as {@link CffuFactory#allTupleOfFastFail(CompletableFuture, CompletableFuture)}, + * This method is the same as {@link CffuFactory#allTupleOfFastFail(CompletionStage, CompletionStage)}, * providing this method is convenient for method chaining. *

* Calling this method @@ -643,38 +601,18 @@ public Cffu> allTupleOfFastFail(Cffu cf2) { *

* is the same as: *

- * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu.toCompletableFuture(), cf2);} + * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cf2);} * * @return the new Cffu - * @see CffuFactory#allTupleOfFastFail(CompletableFuture, CompletableFuture) + * @see CffuFactory#allTupleOfFastFail(CompletionStage, CompletionStage) */ @Contract(pure = true) - public Cffu> allTupleOfFastFail(CompletableFuture cf2) { - return fac.allTupleOfFastFail(toCompletableFuture(), cf2); + public Cffu> allTupleOfFastFail(CompletionStage cf2) { + return fac.allTupleOfFastFail(cf, cf2); } /** - * This method is the same as {@link CffuFactory#allTupleOf(Cffu, Cffu, Cffu)}, - * providing this method is convenient for method chaining. - *

- * Calling this method - *

- * {@code allTuple = cffu.allTupleOf(cffu2, cffu3);} - *

- * is the same as: - *

- * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu, cffu2, cffu3);} - * - * @return the new Cffu - * @see CffuFactory#allTupleOf(Cffu, Cffu, Cffu) - */ - @Contract(pure = true) - public Cffu> allTupleOf(Cffu cf2, Cffu cf3) { - return fac.allTupleOf(this, cf2, cf3); - } - - /** - * This method is the same as {@link CffuFactory#allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture)}, + * This method is the same as {@link CffuFactory#allTupleOf(CompletionStage, CompletionStage, CompletionStage)}, * providing this method is convenient for method chaining. *

* Calling this method @@ -683,38 +621,19 @@ public Cffu> allTupleOf(Cffu cf2, Cffu cf3) { *

* is the same as: *

- * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu.toCompletableFuture(), cf2, cf3);} - * - * @return the new Cffu - * @see CffuFactory#allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture) - */ - @Contract(pure = true) - public Cffu> allTupleOf(CompletableFuture cf2, CompletableFuture cf3) { - return fac.allTupleOf(toCompletableFuture(), cf2, cf3); - } - - /** - * This method is the same as {@link CffuFactory#allTupleOfFastFail(Cffu, Cffu, Cffu)}, - * providing this method is convenient for method chaining. - *

- * Calling this method - *

- * {@code allTuple = cffu.allTupleOfFastFail(cffu2, cffu3);} - *

- * is the same as: - *

- * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cffu2, cffu3);} + * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu, cf2, cf3);} * * @return the new Cffu - * @see CffuFactory#allTupleOfFastFail(Cffu, Cffu, Cffu) + * @see CffuFactory#allTupleOf(CompletionStage, CompletionStage, CompletionStage) */ @Contract(pure = true) - public Cffu> allTupleOfFastFail(Cffu cf2, Cffu cf3) { - return fac.allTupleOfFastFail(this, cf2, cf3); + public Cffu> allTupleOf( + CompletionStage cf2, CompletionStage cf3) { + return fac.allTupleOf(cf, cf2, cf3); } /** - * This method is the same as {@link CffuFactory#allTupleOfFastFail(CompletableFuture, CompletableFuture, CompletableFuture)}, + * This method is the same as {@link CffuFactory#allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage)}, * providing this method is convenient for method chaining. *

* Calling this method @@ -723,38 +642,19 @@ public Cffu> allTupleOfFastFail(Cffu cf2, Cffu * is the same as: *

- * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu.toCompletableFuture(), cf2, cf3);} - * - * @return the new Cffu - * @see CffuFactory#allTupleOfFastFail(CompletableFuture, CompletableFuture, CompletableFuture) - */ - @Contract(pure = true) - public Cffu> allTupleOfFastFail(CompletableFuture cf2, CompletableFuture cf3) { - return fac.allTupleOfFastFail(toCompletableFuture(), cf2, cf3); - } - - /** - * This method is the same as {@link CffuFactory#allTupleOf(Cffu, Cffu, Cffu, Cffu)}, - * providing this method is convenient for method chaining. - *

- * Calling this method - *

- * {@code allTuple = cffu.allTupleOf(cffu2, cffu3, cffu4);} - *

- * is the same as: - *

- * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu, cffu2, cffu3, cffu4);} + * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cf2, cf3);} * * @return the new Cffu - * @see CffuFactory#allTupleOf(Cffu, Cffu, Cffu, Cffu) + * @see CffuFactory#allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage) */ @Contract(pure = true) - public Cffu> allTupleOf(Cffu cf2, Cffu cf3, Cffu cf4) { - return fac.allTupleOf(this, cf2, cf3, cf4); + public Cffu> allTupleOfFastFail( + CompletionStage cf2, CompletionStage cf3) { + return fac.allTupleOfFastFail(cf, cf2, cf3); } /** - * This method is the same as {@link CffuFactory#allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture)}, + * This method is the same as {@link CffuFactory#allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage)}, * providing this method is convenient for method chaining. *

* Calling this method @@ -763,39 +663,19 @@ public Cffu> allTupleOf(Cffu cf2, Cffu * is the same as: *

- * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu.toCompletableFuture(), cf2, cf3, cf4);} + * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu, cf2, cf3, cf4);} * * @return the new Cffu - * @see CffuFactory#allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) + * @see CffuFactory#allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage) */ @Contract(pure = true) public Cffu> allTupleOf( - CompletableFuture cf2, CompletableFuture cf3, CompletableFuture cf4) { - return fac.allTupleOf(toCompletableFuture(), cf2, cf3, cf4); + CompletionStage cf2, CompletionStage cf3, CompletionStage cf4) { + return fac.allTupleOf(cf, cf2, cf3, cf4); } /** - * This method is the same as {@link CffuFactory#allTupleOfFastFail(Cffu, Cffu, Cffu, Cffu)}, - * providing this method is convenient for method chaining. - *

- * Calling this method - *

- * {@code allTuple = cffu.allTupleOfFastFail(cffu2, cffu3, cffu4);} - *

- * is the same as: - *

- * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cffu2, cffu3, cffu4);} - * - * @return the new Cffu - * @see CffuFactory#allTupleOfFastFail(Cffu, Cffu, Cffu, Cffu) - */ - @Contract(pure = true) - public Cffu> allTupleOfFastFail(Cffu cf2, Cffu cf3, Cffu cf4) { - return fac.allTupleOfFastFail(this, cf2, cf3, cf4); - } - - /** - * This method is the same as {@link CffuFactory#allTupleOfFastFail(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture)}, + * This method is the same as {@link CffuFactory#allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage)}, * providing this method is convenient for method chaining. *

* Calling this method @@ -804,40 +684,19 @@ public Cffu> allTupleOfFastFail(Cffu cf2, *

* is the same as: *

- * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu.toCompletableFuture(), cf2, cf3, cf4);} + * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cf2, cf3, cf4);} * * @return the new Cffu - * @see CffuFactory#allTupleOfFastFail(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) + * @see CffuFactory#allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage) */ @Contract(pure = true) public Cffu> allTupleOfFastFail( - CompletableFuture cf2, CompletableFuture cf3, CompletableFuture cf4) { - return fac.allTupleOfFastFail(toCompletableFuture(), cf2, cf3, cf4); + CompletionStage cf2, CompletionStage cf3, CompletionStage cf4) { + return fac.allTupleOfFastFail(cf, cf2, cf3, cf4); } /** - * This method is the same as {@link CffuFactory#allTupleOf(Cffu, Cffu, Cffu, Cffu, Cffu)}, - * providing this method is convenient for method chaining. - *

- * Calling this method - *

- * {@code allTuple = cffu.allTupleOf(cffu2, cffu3, cffu4, cffu5);} - *

- * is the same as: - *

- * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu, cffu2, cffu3, cffu4, cffu5);} - * - * @return the new Cffu - * @see CffuFactory#allTupleOf(Cffu, Cffu, Cffu, Cffu, Cffu) - */ - @Contract(pure = true) - public Cffu> allTupleOf( - Cffu cf2, Cffu cf3, Cffu cf4, Cffu cf5) { - return fac.allTupleOf(this, cf2, cf3, cf4, cf5); - } - - /** - * This method is the same as {@link CffuFactory#allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture)}, + * This method is the same as {@link CffuFactory#allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage)}, * providing this method is convenient for method chaining. *

* Calling this method @@ -846,40 +705,20 @@ public Cffu> allTupleOf( *

* is the same as: *

- * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu.toCompletableFuture(), cf2, cf3, cf4, cf5);} + * {@code allTuple = cffu.cffuFactory().allTupleOf(cffu, cf2, cf3, cf4, cf5);} * * @return the new Cffu - * @see CffuFactory#allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) + * @see CffuFactory#allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage) */ @Contract(pure = true) public Cffu> allTupleOf( - CompletableFuture cf2, CompletableFuture cf3, CompletableFuture cf4, CompletableFuture cf5) { - return fac.allTupleOf(toCompletableFuture(), cf2, cf3, cf4, cf5); - } - - /** - * This method is the same as {@link CffuFactory#allTupleOfFastFail(Cffu, Cffu, Cffu, Cffu, Cffu)}, - * providing this method is convenient for method chaining. - *

- * Calling this method - *

- * {@code allTuple = cffu.allTupleOfFastFail(cffu2, cffu3, cffu4, cffu5);} - *

- * is the same as: - *

- * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cffu2, cffu3, cffu4, cffu5);} - * - * @return the new Cffu - * @see CffuFactory#allTupleOfFastFail(Cffu, Cffu, Cffu, Cffu, Cffu) - */ - @Contract(pure = true) - public Cffu> allTupleOfFastFail( - Cffu cf2, Cffu cf3, Cffu cf4, Cffu cf5) { - return fac.allTupleOfFastFail(this, cf2, cf3, cf4, cf5); + CompletionStage cf2, CompletionStage cf3, + CompletionStage cf4, CompletionStage cf5) { + return fac.allTupleOf(cf, cf2, cf3, cf4, cf5); } /** - * This method is the same as {@link CffuFactory#allTupleOfFastFail(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture)}, + * This method is the same as {@link CffuFactory#allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage)}, * providing this method is convenient for method chaining. *

* Calling this method @@ -888,15 +727,16 @@ public Cffu> allTupleOfFastFail( *

* is the same as: *

- * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu.toCompletableFuture(), cf2, cf3, cf4, cf5);} + * {@code allTuple = cffu.cffuFactory().allTupleOfFastFail(cffu, cf2, cf3, cf4, cf5);} * * @return the new Cffu - * @see CffuFactory#allTupleOfFastFail(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) + * @see CffuFactory#allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage) */ @Contract(pure = true) public Cffu> allTupleOfFastFail( - CompletableFuture cf2, CompletableFuture cf3, CompletableFuture cf4, CompletableFuture cf5) { - return fac.allTupleOfFastFail(toCompletableFuture(), cf2, cf3, cf4, cf5); + CompletionStage cf2, CompletionStage cf3, + CompletionStage cf4, CompletionStage cf5) { + return fac.allTupleOfFastFail(cf, cf2, cf3, cf4, cf5); } //////////////////////////////////////////////////////////////////////////////// diff --git a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java index c5ac38b2..8a51584c 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -299,253 +299,95 @@ public final Cffu[] asCffuArray(CompletionStage... stages) { //////////////////////////////////////////////////////////////////////////////// /** - * Returns a new Cffu that is completed when all the given Cffus complete. - * If any of the given Cffu complete exceptionally, then the returned + * Returns a new Cffu that is completed when all the given stages complete. + * If any of the given stages complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause.
- * Otherwise, the results, if any, of the given Cffus are not reflected in + * Otherwise, the results, if any, of the given stages are not reflected in * the returned Cffu({@code Cffu}), but may be obtained by inspecting them individually.
- * If no Cffus are provided, returns a Cffu completed with the value {@code null}. + * If no stages are provided, returns a Cffu completed with the value {@code null}. *

- * if you need the results of given Cffus, prefer below methods: + * if you need the results of given stages, prefer below methods: *

    - *
  1. {@link #allResultsOf(Cffu[])} - *
  2. {@link #allTupleOf(Cffu, Cffu)} / {@link #allTupleOf(Cffu, Cffu, Cffu, Cffu, Cffu)} + *
  3. {@link #allResultsOf(CompletionStage[])} + *
  4. {@link #allTupleOf(CompletionStage, CompletionStage)} / + * {@link #allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage)} * (provided overloaded methods with 2~5 input) *
- *

- * Among the applications of this method is to await completion of a set of - * independent Cffus before continuing a program, - * as in: {@code CffuFactory.allOf(c1, c2, c3).join();}. * - * @param cfs the Cffus - * @return a new Cffu that is completed when all the given Cffus complete + * @param cfs the stages + * @return a new Cffu that is completed when all the given stages complete * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #allResultsOf(Cffu[]) - * @see #allTupleOf(Cffu, Cffu) - * @see #allTupleOf(Cffu, Cffu, Cffu) - * @see #allTupleOf(Cffu, Cffu, Cffu, Cffu) - * @see #allTupleOf(Cffu, Cffu, Cffu, Cffu, Cffu) + * @see #allResultsOf(CompletionStage[]) + * @see #allTupleOf(CompletionStage, CompletionStage) + * @see #allTupleOf(CompletionStage, CompletionStage, CompletionStage) + * @see #allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage) + * @see #allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage) * @see CompletableFuture#allOf(CompletableFuture[]) */ @Contract(pure = true) - @SuppressWarnings("unchecked") - public Cffu allOf(Cffu... cfs) { - return allOf(toCompletableFutureArray((Cffu[]) cfs)); - } - - /** - * Returns a new Cffu that is completed when all the given CompletableFutures complete. - * If any of the given CompletableFuture complete exceptionally, then the returned - * Cffu also does so, with a CompletionException holding this exception as its cause.
- * Otherwise, the results, if any, of the given CompletableFutures are not reflected in - * the returned Cffu({@code Cffu}), but may be obtained by inspecting them individually.
- * If no CompletableFutures are provided, returns a Cffu completed with the value {@code null}. - *

- * This method is the same as {@link #allOf(Cffu[])} with overloaded argument type {@link CompletableFuture}. - *

- * if you need the results of given CompletableFutures, prefer below methods: - *

    - *
  1. {@link #allResultsOf(CompletableFuture[])} - *
  2. {@link #allTupleOf(CompletableFuture, CompletableFuture)} / - * {@link #allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture)} - * (provided overloaded methods with 2~5 input) - *
- * - * @param cfs the CompletableFutures - * @return a new Cffu that is completed when all the given CompletableFutures complete - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #allOf(Cffu[]) - * @see #allResultsOf(CompletableFuture[]) - * @see #allTupleOf(CompletableFuture, CompletableFuture) - * @see #allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture) - * @see #allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) - * @see #allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) - * @see CompletableFuture#allOf(CompletableFuture[]) - */ - @Contract(pure = true) - public Cffu allOf(CompletableFuture... cfs) { - return new0(CompletableFuture.allOf(cfs)); - } - - /** - * Provided this overloaded method just for resolving "allOf is ambiguous" problem - * when call {@code allOf} with empty arguments: {@code cffuFactory.allOf()}. - * - * @see #allOf(Cffu[]) - * @see #allOf(CompletableFuture[]) - */ - @Contract(pure = true) - public Cffu allOf() { - return dummy(); - } - - /** - * Returns a new Cffu that is successful when all the given Cffus success, - * the results({@code Cffu}) of the given Cffus are not reflected - * in the returned Cffu, but may be obtained by inspecting them individually. - * If any of the given Cffus complete exceptionally, then the returned Cffu - * also does so *without* waiting other incomplete given Cffus, - * with a CompletionException holding this exception as its cause. - * If no Cffus are provided, returns a Cffu completed with the value {@code null}. - * - * @param cfs the Cffus - * @return a new Cffu that is successful when all the given Cffus success - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see CompletableFutureUtils#allOfFastFail(CompletableFuture[]) - */ - @Contract(pure = true) - @SuppressWarnings("unchecked") - public Cffu allOfFastFail(Cffu... cfs) { - return allOfFastFail(toCompletableFutureArray((Cffu[]) cfs)); + @SuppressWarnings({"unchecked", "rawtypes"}) + public Cffu allOf(CompletionStage... cfs) { + return new0(CompletableFuture.allOf(toCompletableFutureArray((CompletionStage[]) cfs))); } /** - * Returns a new Cffu that is successful when all the given CompletableFutures success, - * the results({@code Cffu}) of the given CompletableFutures are not reflected + * Returns a new Cffu that is successful when all the given stages success, + * the results({@code Cffu}) of the given stages are not reflected * in the returned Cffu, but may be obtained by inspecting them individually. - * If any of the given CompletableFutures complete exceptionally, then the returned Cffu - * also does so *without* waiting other incomplete given CompletableFutures, + * If any of the given stages complete exceptionally, then the returned Cffu + * also does so *without* waiting other incomplete given stages, * with a CompletionException holding this exception as its cause. - * If no CompletableFutures are provided, returns a Cffu completed with the value {@code null}. - *

- * This method is the same as {@link #allOfFastFail(Cffu[])} - * except with overloaded argument type {@link CompletableFuture}. + * If no stages are provided, returns a Cffu completed with the value {@code null}. * - * @param cfs the CompletableFutures - * @return a new Cffu that is successful when all the given CompletableFutures success + * @param cfs the stages + * @return a new Cffu that is successful when all the given stages success * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #allOfFastFail(Cffu[]) - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see CompletableFutureUtils#allOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see CompletableFutureUtils#allOfFastFail(CompletionStage[]) */ @Contract(pure = true) - public Cffu allOfFastFail(CompletableFuture... cfs) { + public Cffu allOfFastFail(CompletionStage... cfs) { return new0(CompletableFutureUtils.allOfFastFail(cfs)); } /** - * Provided this overloaded method just for resolving "allOfFastFail is ambiguous" problem - * when call {@code allOfFastFail} with empty arguments: {@code cffuFactory.allOfFastFail()}. - * - * @see #allOfFastFail(Cffu[]) - * @see #allOfFastFail(CompletableFuture[]) - */ - @Contract(pure = true) - public Cffu allOfFastFail() { - return new0(CompletableFutureUtils.allOfFastFail()); - } - - /** - * Returns a new Cffu with the results in the same order of all the given Cffus, - * the new Cffu is completed when all the given Cffus complete. - * Returns a new Cffu that is completed when all the given Cffus complete. - * If any of the given Cffus complete exceptionally, then the returned Cffu + * Returns a new Cffu with the results in the same order of all the given stages, + * the new Cffu is completed when all the given stages complete. + * If any of the given stages complete exceptionally, then the returned Cffu * also does so, with a CompletionException holding this exception as its cause. - * If no Cffus are provided, returns a Cffu completed with the value empty list. - *

- * This method is the same as {@link #allOf(Cffu[])}, except the returned Cffu contains the results of input Cffus. + * If no stages are provided, returns a Cffu completed with the value empty list. * - * @param cfs the Cffus - * @return a new Cffu that is completed when all the given Cffus complete + * @param cfs the stages + * @return a new Cffu that is completed when all the given stages complete * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #allOf(Cffu[]) + * @see #allResultsOf(CompletionStage[]) */ @Contract(pure = true) @SafeVarargs - @SuppressWarnings({"rawtypes", "unchecked"}) - public final Cffu> allResultsOf(Cffu... cfs) { - return allResultsOf(toCompletableFutureArray((Cffu[]) cfs)); - } - - /** - * Returns a new Cffu with the results in the same order of all the given CompletableFutures, - * the new Cffu is completed when all the given CompletableFutures complete. - * If any of the given CompletableFutures complete exceptionally, then the returned Cffu - * also does so, with a CompletionException holding this exception as its cause. - * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. - *

- * This method is the same as {@link #allResultsOf(Cffu[])} - * except with overloaded argument type {@link CompletableFuture}. - * - * @param cfs the CompletableFutures - * @return a new Cffu that is completed when all the given CompletableFutures complete - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #allResultsOf(Cffu[]) - */ - @Contract(pure = true) - @SafeVarargs - public final Cffu> allResultsOf(CompletableFuture... cfs) { + public final Cffu> allResultsOf(CompletionStage... cfs) { return new0(CompletableFutureUtils.allResultsOf(cfs)); } /** - * Provided this overloaded method just for resolving "allResultsOf is ambiguous" problem - * when call {@code allResultsOf} with empty arguments: {@code cffuFactory.allResultsOf()}. - * - * @see #allResultsOf(Cffu[]) - * @see #allResultsOf(CompletableFuture[]) - */ - @Contract(pure = true) - public Cffu> allResultsOf() { - return new0(CompletableFutureUtils.allResultsOf()); - } - - /** - * Returns a new Cffu with the results in the same order of all the given Cffus, - * the new Cffu success when all the given Cffus success. - * If any of the given Cffus complete exceptionally, then the returned Cffu - * also does so *without* waiting other incomplete given Cffus, + * Returns a new Cffu with the results in the same order of all the given stages, + * the new Cffu success when all the given stages success. + * If any of the given stages complete exceptionally, then the returned Cffu + * also does so *without* waiting other incomplete given stages, * with a CompletionException holding this exception as its cause. - * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. + * If no stages are provided, returns a Cffu completed with the value empty list. * - * @param cfs the CompletableFutures - * @return a new CompletableFuture that is successful when all the given CompletableFutures success + * @param cfs the stages + * @return a new Cffu that is successful when all the given stages success * @throws NullPointerException if the array or any of its elements are {@code null} - * @see CompletableFutureUtils#allOfFastFail(CompletableFuture[]) - * @see #allResultsOfFastFail(Cffu[]) + * @see CompletableFutureUtils#allOfFastFail(CompletionStage[]) + * @see #allResultsOfFastFail(CompletionStage[]) */ @Contract(pure = true) @SafeVarargs - @SuppressWarnings({"rawtypes", "unchecked"}) - public final Cffu> allResultsOfFastFail(Cffu... cfs) { - return allResultsOfFastFail(toCompletableFutureArray((Cffu[]) cfs)); - } - - /** - * Returns a new Cffu with the results in the same order of all the given CompletableFutures, - * the new Cffu success when all the given CompletableFutures success. - * If any of the given CompletableFutures complete exceptionally, then the returned Cffu - * also does so *without* waiting other incomplete given CompletableFutures, - * with a CompletionException holding this exception as its cause. - * If no CompletableFutures are provided, returns a Cffu completed with the value empty list. - *

- * This method is the same as {@link #allResultsOfFastFail(Cffu[])} - * except with overloaded argument type {@link CompletableFuture}. - * - * @param cfs the CompletableFutures - * @return a new CompletableFuture that is successful when all the given CompletableFutures success - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see CompletableFutureUtils#allOfFastFail(CompletableFuture[]) - * @see #allResultsOfFastFail(Cffu[]) - */ - @Contract(pure = true) - @SafeVarargs - public final Cffu> allResultsOfFastFail(CompletableFuture... cfs) { + public final Cffu> allResultsOfFastFail(CompletionStage... cfs) { return new0(CompletableFutureUtils.allResultsOfFastFail(cfs)); } - /** - * Provided this overloaded method just for resolving "allResultsOfFastFail is ambiguous" problem - * when call {@code allResultsOfFastFail} with empty arguments: {@code cffuFactory.allResultsOfFastFail()}. - * - * @see #allResultsOfFastFail(Cffu[]) - * @see #allResultsOfFastFail(CompletableFuture[]) - */ - @Contract(pure = true) - public Cffu> allResultsOfFastFail() { - return new0(CompletableFutureUtils.allResultsOfFastFail()); - } - //////////////////////////////////////////////////////////////////////////////// //# anyOf* methods: // @@ -554,96 +396,41 @@ public Cffu> allResultsOfFastFail() { //////////////////////////////////////////////////////////////////////////////// /** - * Returns a new Cffu that is completed when any of the given Cffus complete, with the same result.
+ * Returns a new Cffu that is completed when any of the given stages complete, with the same result.
* Otherwise, if it completed exceptionally, the returned Cffu also does so, * with a CompletionException holding this exception as its cause.
- * If no Cffus are provided, returns an incomplete Cffu. - * - * @param cfs the Cffus - * @return a new Cffu that is completed with the result - * or exception from any of the given Cffus when one completes - * @throws NullPointerException if the array or any of its elements are {@code null} - * @see CompletableFuture#anyOf(CompletableFuture[]) - */ - @Contract(pure = true) - @SuppressWarnings("unchecked") - @SafeVarargs - public final Cffu anyOf(Cffu... cfs) { - return anyOf(toCompletableFutureArray((Cffu[]) cfs)); - } - - /** - * This method is the same as {@link #anyOf(Cffu[])} except with overloaded argument type {@link CompletableFuture}. + * If no stages are provided, returns an incomplete Cffu. * - * @param cfs the CompletableFutures + * @param cfs the stages * @return a new Cffu that is completed with the result - * or exception from any of the given CompletableFutures when one completes + * or exception from any of the given stages when one completes * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #anyOf(Cffu[]) + * @see #anyOf(CompletionStage[]) * @see CompletableFuture#anyOf(CompletableFuture[]) */ @Contract(pure = true) - @SuppressWarnings("unchecked") @SafeVarargs - public final Cffu anyOf(CompletableFuture... cfs) { - return (Cffu) new0(CompletableFuture.anyOf(cfs)); + public final Cffu anyOf(CompletionStage... cfs) { + return new0(CompletableFutureUtils.anyOf(cfs)); } /** - * Provided this overloaded method just for resolving "anyOf is ambiguous" problem - * when call {@code anyOf} with empty arguments: {@code cffuFactory.anyOf()}. - * - * @see #anyOf(Cffu[]) - * @see #anyOf(CompletableFuture[]) - */ - @Contract(pure = true) - public Cffu anyOf() { - return newIncompleteCffu(); - } - - /** - * Returns a new Cffu that is successful when any of the given Cffus success, - * with the same result. Otherwise, all the given Cffus complete exceptionally, + * Returns a new Cffu that is successful when any of the given stages success, + * with the same result. Otherwise, all the given stages complete exceptionally, * the returned Cffu also does so, with a CompletionException holding - * an exception from any of the given Cffu as its cause. If no Cffu are provided, + * an exception from any of the given stages as its cause. If no stages are provided, * returns a new Cffu that is already completed exceptionally * with a CompletionException holding a {@link NoCfsProvidedException} as its cause. * - * @param cfs the Cffus + * @param cfs the stages * @return a new Cffu * @throws NullPointerException if the array or any of its elements are {@code null} */ - @SuppressWarnings({"unchecked", "rawtypes"}) @SafeVarargs - public final Cffu anyOfSuccess(Cffu... cfs) { - return (Cffu) anyOfSuccess(toCompletableFutureArray((Cffu[]) cfs)); - } - - /** - * Returns a new Cffu that is successful when any of the given CompletableFutures success, - * with the same result. Otherwise, all the given CompletableFutures complete exceptionally, - * the returned Cffu also does so, with a CompletionException holding - * an exception from any of the given CompletableFutures as its cause. If no CompletableFutures are provided, - * returns a new Cffu that is already completed exceptionally - * with a CompletionException holding a {@link NoCfsProvidedException} as its cause. - * - * @param cfs the CompletableFutures - * @return a new Cffu - * @throws NullPointerException if the array or any of its elements are {@code null} - */ - @SafeVarargs - public final Cffu anyOfSuccess(CompletableFuture... cfs) { + public final Cffu anyOfSuccess(CompletionStage... cfs) { return new0(CompletableFutureUtils.anyOfSuccess(cfs)); } - /** - * Provided this overloaded method just for resolving "anyOfSuccess is ambiguous" problem - * when call {@code anyOfSuccess} with empty arguments: {@code cffuFactory.anyOfSuccess()}. - */ - public Cffu anyOfSuccess() { - return new0(CompletableFutureUtils.anyOfSuccess()); - } - //////////////////////////////////////////////////////////////////////////////// //# New type-safe allTupleOf Factory Methods, support 2~5 input arguments // @@ -651,62 +438,22 @@ public Cffu anyOfSuccess() { // - allTupleOfFastFail //////////////////////////////////////////////////////////////////////////////// - /** - * Returns a new Cffu that is completed when the given two Cffus complete. - * If any of the given Cffu complete exceptionally, then the returned - * Cffu also does so, with a CompletionException holding this exception as its cause. - *

- * This method is the same as {@link #allResultsOf(Cffu[])} - * except with two inputs and return results as {@code Tuple2}. - * - * @return a new Cffu that is completed when the given two Cffus complete - * @throws NullPointerException if any input Cffus are {@code null} - * @see Cffu#allTupleOf(Cffu) - * @see #allResultsOf(Cffu[]) - * @see #allOf(Cffu[]) - */ - @Contract(pure = true) - public Cffu> allTupleOf(Cffu cf1, Cffu cf2) { - return allTupleOf(cf1.toCompletableFuture(), cf2.toCompletableFuture()); - } - /** * Returns a new Cffu that is completed when the given two CompletableFutures complete. * If any of the given CompletableFutures complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause. - *

- * This method is the same as {@link #allTupleOf(Cffu, Cffu)} - * except with overloaded argument type {@link CompletableFuture}. * * @return a new Cffu that is completed when the given 2 CompletableFutures complete * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see Cffu#allTupleOf(CompletableFuture) - * @see #allTupleOf(Cffu, Cffu) - * @see #allResultsOf(CompletableFuture[]) - * @see #allOf(CompletableFuture[]) + * @see Cffu#allTupleOf(CompletionStage) + * @see #allResultsOf(CompletionStage[]) + * @see #allOf(CompletionStage[]) */ @Contract(pure = true) - public Cffu> allTupleOf(CompletableFuture cf1, CompletableFuture cf2) { + public Cffu> allTupleOf(CompletionStage cf1, CompletionStage cf2) { return new0(CompletableFutureUtils.allTupleOf(cf1, cf2)); } - /** - * Returns a new Cffu that is successful when the given two Cffus success. - * If any of the given Cffus complete exceptionally, then the returned - * Cffu also does so *without* waiting other incomplete given Cffus, - * with a CompletionException holding this exception as its cause. - * - * @return a new Cffu that is successful when the given two Cffus success - * @throws NullPointerException if any of the given Cffus are {@code null} - * @see Cffu#allTupleOfFastFail(Cffu) - * @see #allResultsOfFastFail(Cffu[]) - * @see #allOfFastFail(Cffu[]) - */ - @Contract(pure = true) - public Cffu> allTupleOfFastFail(Cffu cf1, Cffu cf2) { - return allTupleOfFastFail(cf1.toCompletableFuture(), cf2.toCompletableFuture()); - } - /** * Returns a new Cffu that is successful when the given two CompletableFutures success. * If any of the given CompletableFutures complete exceptionally, then the returned @@ -715,73 +462,32 @@ public Cffu> allTupleOfFastFail(Cffu cf1, Cffu c * * @return a new Cffu that is successful when the given two CompletableFutures success * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see Cffu#allTupleOfFastFail(CompletableFuture) - * @see #allTupleOfFastFail(Cffu, Cffu) - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see #allOfFastFail(CompletableFuture[]) + * @see Cffu#allTupleOfFastFail(CompletionStage) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) - public Cffu> allTupleOfFastFail(CompletableFuture cf1, CompletableFuture cf2) { + public Cffu> allTupleOfFastFail(CompletionStage cf1, CompletionStage cf2) { return new0(CompletableFutureUtils.allTupleOfFastFail(cf1, cf2)); } - /** - * Returns a new Cffu that is completed when the given three Cffus complete. - * If any of the given Cffu complete exceptionally, then the returned - * Cffu also does so, with a CompletionException holding this exception as its cause. - *

- * This method is the same as {@link #allResultsOf(Cffu[])} - * except with three inputs and return results as {@code Tuple3}. - * - * @return a new Cffu that is completed when the given three Cffus complete - * @throws NullPointerException if any input Cffus are {@code null} - * @see Cffu#allTupleOf(Cffu, Cffu) - * @see #allResultsOf(Cffu[]) - * @see #allOf(Cffu[]) - */ - @Contract(pure = true) - public Cffu> allTupleOf(Cffu cf1, Cffu cf2, Cffu cf3) { - return allTupleOf(cf1.toCompletableFuture(), cf2.toCompletableFuture(), cf3.toCompletableFuture()); - } - /** * Returns a new Cffu that is completed when the given three CompletableFutures complete. * If any of the given CompletableFutures complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause. - *

- * This method is the same as {@link #allTupleOf(Cffu, Cffu, Cffu)} - * except with overloaded argument type {@link CompletableFuture}. * * @return a new Cffu that is completed when the given 3 CompletableFutures complete * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see Cffu#allTupleOf(CompletableFuture, CompletableFuture) - * @see #allTupleOf(Cffu, Cffu, Cffu) - * @see #allResultsOf(CompletableFuture[]) - * @see #allOf(CompletableFuture[]) + * @see Cffu#allTupleOf(CompletionStage, CompletionStage) + * @see #allResultsOf(CompletionStage[]) + * @see #allOf(CompletionStage[]) */ @Contract(pure = true) public Cffu> allTupleOf( - CompletableFuture cf1, CompletableFuture cf2, CompletableFuture cf3) { + CompletionStage cf1, CompletionStage cf2, CompletionStage cf3) { return new0(CompletableFutureUtils.allTupleOf(cf1, cf2, cf3)); } - /** - * Returns a new Cffu that is successful when the given three Cffus success. - * If any of the given Cffus complete exceptionally, then the returned - * Cffu also does so *without* waiting other incomplete given Cffus, - * with a CompletionException holding this exception as its cause. - * - * @return a new Cffu that is successful when the given three Cffus success - * @throws NullPointerException if any of the given Cffus are {@code null} - * @see Cffu#allTupleOfFastFail(Cffu, Cffu) - * @see #allResultsOfFastFail(Cffu[]) - * @see #allOfFastFail(Cffu[]) - */ - @Contract(pure = true) - public Cffu> allTupleOfFastFail(Cffu cf1, Cffu cf2, Cffu cf3) { - return allTupleOfFastFail(cf1.toCompletableFuture(), cf2.toCompletableFuture(), cf3.toCompletableFuture()); - } - /** * Returns a new Cffu that is successful when the given three CompletableFutures success. * If any of the given CompletableFutures complete exceptionally, then the returned @@ -790,80 +496,35 @@ public Cffu> allTupleOfFastFail(Cffu cf1, Cf * * @return a new Cffu that is successful when the given three CompletableFutures success * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see Cffu#allTupleOfFastFail(CompletableFuture, CompletableFuture) - * @see #allTupleOfFastFail(Cffu, Cffu) - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see #allOfFastFail(CompletableFuture[]) + * @see Cffu#allTupleOfFastFail(CompletionStage, CompletionStage) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) public Cffu> allTupleOfFastFail( - CompletableFuture cf1, CompletableFuture cf2, CompletableFuture cf3) { + CompletionStage cf1, CompletionStage cf2, CompletionStage cf3) { return new0(CompletableFutureUtils.allTupleOfFastFail(cf1, cf2, cf3)); } - /** - * Returns a new Cffu that is completed when the given 4 Cffus complete. - * If any of the given Cffu complete exceptionally, then the returned - * Cffu also does so, with a CompletionException holding this exception as its cause. - *

- * This method is the same as {@link #allResultsOf(Cffu[])} - * except with 4 inputs and return results as {@code Tuple4}. - * - * @return a new Cffu that is completed when the given 4 Cffus complete - * @throws NullPointerException if any input Cffus are {@code null} - * @see Cffu#allTupleOf(Cffu, Cffu, Cffu) - * @see #allResultsOf(Cffu[]) - * @see #allOf(Cffu[]) - */ - @Contract(pure = true) - public Cffu> allTupleOf( - Cffu cf1, Cffu cf2, Cffu cf3, Cffu cf4) { - return allTupleOf(cf1.toCompletableFuture(), cf2.toCompletableFuture(), - cf3.toCompletableFuture(), cf4.toCompletableFuture()); - } - /** * Returns a new Cffu that is completed when the given 4 CompletableFutures complete. * If any of the given CompletableFutures complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause. - *

- * This method is the same as {@link #allTupleOf(Cffu, Cffu, Cffu, Cffu)} - * except with overloaded argument type {@link CompletableFuture}. * * @return a new Cffu that is completed when the given 4 CompletableFutures complete * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see Cffu#allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture) - * @see #allTupleOf(Cffu, Cffu, Cffu, Cffu) - * @see #allResultsOf(CompletableFuture[]) - * @see #allOf(CompletableFuture[]) + * @see Cffu#allTupleOf(CompletionStage, CompletionStage, CompletionStage) + * @see #allResultsOf(CompletionStage[]) + * @see #allOf(CompletionStage[]) */ @Contract(pure = true) public Cffu> allTupleOf( - CompletableFuture cf1, CompletableFuture cf2, - CompletableFuture cf3, CompletableFuture cf4) { + CompletionStage cf1, CompletionStage cf2, + CompletionStage cf3, CompletionStage cf4) { return new0(CompletableFutureUtils.allTupleOf(cf1, cf2, cf3, cf4)); } - /** - * Returns a new Cffu that is successful when the given four Cffus success. - * If any of the given Cffus complete exceptionally, then the returned - * Cffu also does so *without* waiting other incomplete given Cffus, - * with a CompletionException holding this exception as its cause. - * - * @return a new Cffu that is successful when the given four Cffus success - * @throws NullPointerException if any of the given Cffus are {@code null} - * @see Cffu#allTupleOfFastFail(Cffu, Cffu, Cffu) - * @see #allResultsOfFastFail(Cffu[]) - * @see #allOfFastFail(Cffu[]) - */ - @Contract(pure = true) - public Cffu> allTupleOfFastFail( - Cffu cf1, Cffu cf2, Cffu cf3, Cffu cf4) { - return allTupleOfFastFail(cf1.toCompletableFuture(), cf2.toCompletableFuture(), - cf3.toCompletableFuture(), cf4.toCompletableFuture()); - } - /** * Returns a new Cffu that is successful when the given four CompletableFutures success. * If any of the given CompletableFutures complete exceptionally, then the returned @@ -872,80 +533,35 @@ public Cffu> allTupleOfFastFail( * * @return a new Cffu that is successful when the given four CompletableFutures success * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see Cffu#allTupleOfFastFail(CompletableFuture, CompletableFuture, CompletableFuture) - * @see #allTupleOfFastFail(Cffu, Cffu) - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see #allOfFastFail(CompletableFuture[]) + * @see Cffu#allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) public Cffu> allTupleOfFastFail( - CompletableFuture cf1, CompletableFuture cf2, - CompletableFuture cf3, CompletableFuture cf4) { + CompletionStage cf1, CompletionStage cf2, + CompletionStage cf3, CompletionStage cf4) { return new0(CompletableFutureUtils.allTupleOfFastFail(cf1, cf2, cf3, cf4)); } - /** - * Returns a new Cffu that is completed when the given 5 Cffus complete. - * If any of the given Cffu complete exceptionally, then the returned - * Cffu also does so, with a CompletionException holding this exception as its cause. - *

- * This method is the same as {@link #allResultsOf(Cffu[])} - * except with 5 inputs and return results as {@code Tuple5}. - * - * @return a new Cffu that is completed when the given 5 Cffus complete - * @throws NullPointerException if any input Cffus are {@code null} - * @see Cffu#allTupleOf(Cffu, Cffu, Cffu, Cffu) - * @see #allResultsOf(Cffu[]) - * @see #allOf(Cffu[]) - */ - @Contract(pure = true) - public Cffu> allTupleOf( - Cffu cf1, Cffu cf2, Cffu cf3, Cffu cf4, Cffu cf5) { - return allTupleOf(cf1.toCompletableFuture(), cf2.toCompletableFuture(), - cf3.toCompletableFuture(), cf4.toCompletableFuture(), cf5.toCompletableFuture()); - } - /** * Returns a new Cffu that is completed when the given 5 CompletableFutures complete. * If any of the given CompletableFutures complete exceptionally, then the returned * Cffu also does so, with a CompletionException holding this exception as its cause. - *

- * This method is the same as {@link #allTupleOf(Cffu, Cffu, Cffu, Cffu, Cffu)} - * except with overloaded argument type {@link CompletableFuture}. * * @return a new Cffu that is completed when the given 5 CompletableFutures complete * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see Cffu#allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) - * @see #allTupleOf(Cffu, Cffu, Cffu, Cffu, Cffu) - * @see #allResultsOf(CompletableFuture[]) - * @see #allOf(CompletableFuture[]) + * @see Cffu#allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage) + * @see #allResultsOf(CompletionStage[]) + * @see #allOf(CompletionStage[]) */ @Contract(pure = true) public Cffu> allTupleOf( - CompletableFuture cf1, CompletableFuture cf2, - CompletableFuture cf3, CompletableFuture cf4, CompletableFuture cf5) { + CompletionStage cf1, CompletionStage cf2, + CompletionStage cf3, CompletionStage cf4, CompletionStage cf5) { return new0(CompletableFutureUtils.allTupleOf(cf1, cf2, cf3, cf4, cf5)); } - /** - * Returns a new Cffu that is successful when the given five Cffus success. - * If any of the given Cffus complete exceptionally, then the returned - * Cffu also does so *without* waiting other incomplete given Cffus, - * with a CompletionException holding this exception as its cause. - * - * @return a new Cffu that is successful when the given five Cffus success - * @throws NullPointerException if any of the given Cffus are {@code null} - * @see Cffu#allTupleOfFastFail(Cffu, Cffu, Cffu, Cffu) - * @see #allResultsOfFastFail(Cffu[]) - * @see #allOfFastFail(Cffu[]) - */ - @Contract(pure = true) - public Cffu> allTupleOfFastFail( - Cffu cf1, Cffu cf2, Cffu cf3, Cffu cf4, Cffu cf5) { - return allTupleOfFastFail(cf1.toCompletableFuture(), cf2.toCompletableFuture(), - cf3.toCompletableFuture(), cf4.toCompletableFuture(), cf5.toCompletableFuture()); - } - /** * Returns a new Cffu that is successful when the given five CompletableFutures success. * If any of the given CompletableFutures complete exceptionally, then the returned @@ -954,15 +570,15 @@ public Cffu> allTupleOfFastFail( * * @return a new Cffu that is successful when the given five CompletableFutures success * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see Cffu#allTupleOfFastFail(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture) - * @see #allTupleOfFastFail(Cffu, Cffu) - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see #allOfFastFail(CompletableFuture[]) + * @see Cffu#allTupleOfFastFail(CompletionStage, CompletionStage, CompletionStage, CompletionStage) + * @see #allTupleOfFastFail(CompletionStage, CompletionStage) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) public Cffu> allTupleOfFastFail( - CompletableFuture cf1, CompletableFuture cf2, - CompletableFuture cf3, CompletableFuture cf4, CompletableFuture cf5) { + CompletionStage cf1, CompletionStage cf2, + CompletionStage cf3, CompletionStage cf4, CompletionStage cf5) { return new0(CompletableFutureUtils.allTupleOfFastFail(cf1, cf2, cf3, cf4, cf5)); } diff --git a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java index 04aac6fe..ab2f9261 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -16,6 +16,7 @@ import java.util.concurrent.*; import java.util.function.*; +import static io.foldright.cffu.CffuFactory.toCompletableFutureArray; import static java.util.Objects.requireNonNull; @@ -48,19 +49,19 @@ public final class CompletableFutureUtils { */ @Contract(pure = true) @SafeVarargs - @SuppressWarnings("unchecked") - public static CompletableFuture> allResultsOf(CompletableFuture... cfs) { + @SuppressWarnings({"unchecked"}) + public static CompletableFuture> allResultsOf(CompletionStage... cfs) { requireCfsAndEleNonNull(cfs); final int size = cfs.length; if (size == 0) return CompletableFuture.completedFuture(arrayList()); - if (size == 1) return cfs[0].thenApply(CompletableFutureUtils::arrayList); + if (size == 1) return csToListCf(cfs[0]); final Object[] result = new Object[size]; final CompletableFuture[] collectResultCfs = new CompletableFuture[size]; for (int i = 0; i < size; i++) { final int index = i; - collectResultCfs[index] = cfs[index].thenAccept(v -> result[index] = v); + collectResultCfs[index] = cfs[index].thenAccept(v -> result[index] = v).toCompletableFuture(); } return CompletableFuture.allOf(collectResultCfs) @@ -85,11 +86,11 @@ public static CompletableFuture> allResultsOf(CompletableFuture allOfFastFail(CompletableFuture... cfs) { + public static CompletableFuture allOfFastFail(CompletionStage... cfs) { requireCfsAndEleNonNull(cfs); final int size = cfs.length; if (size == 0) return CompletableFuture.completedFuture(null); - if (size == 1) return cfs[0].thenApply(v -> null); + if (size == 1) return (CompletableFuture) cfs[0].thenApply(v -> null).toCompletableFuture(); final CompletableFuture[] successOrBeIncomplete = new CompletableFuture[size]; // NOTE: fill ONE MORE element of failedOrBeIncomplete LATER @@ -111,24 +112,24 @@ public static CompletableFuture allOfFastFail(CompletableFuture... cfs) * with a CompletionException holding this exception as its cause. * If no CompletableFutures are provided, returns a CompletableFuture completed with the value empty list. *

- * This method is the same as {@link #allOfFastFail(CompletableFuture[])}, + * This method is the same as {@link #allOfFastFail(CompletionStage[])}, * except the returned CompletableFuture contains the results of the given CompletableFutures. *

- * This method is the same as {@link #allResultsOf(CompletableFuture[])} except for the fast-fail behavior. + * This method is the same as {@link #allResultsOf(CompletionStage[])} except for the fast-fail behavior. * * @param cfs the CompletableFutures * @return a new CompletableFuture that is successful when all the given CompletableFutures success * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #allOfFastFail(CompletableFuture[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) @SafeVarargs @SuppressWarnings({"unchecked", "rawtypes"}) - public static CompletableFuture> allResultsOfFastFail(CompletableFuture... cfs) { + public static CompletableFuture> allResultsOfFastFail(CompletionStage... cfs) { requireCfsAndEleNonNull(cfs); final int size = cfs.length; if (size == 0) return CompletableFuture.completedFuture(arrayList()); - if (size == 1) return cfs[0].thenApply(CompletableFutureUtils::arrayList); + if (size == 1) return csToListCf(cfs[0]); final CompletableFuture[] successOrBeIncomplete = new CompletableFuture[size]; // NOTE: fill ONE MORE element of failedOrBeIncomplete LATER @@ -161,19 +162,24 @@ private static List arrayList(T... elements) { } @SuppressWarnings({"unchecked", "rawtypes"}) - private static void fill(CompletableFuture[] cfs, + private static CompletableFuture> csToListCf(CompletionStage s) { + return (CompletableFuture) s.thenApply(CompletableFutureUtils::arrayList).toCompletableFuture(); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private static void fill(CompletionStage[] cfs, CompletableFuture[] successOrBeIncomplete, CompletableFuture[] failedOrBeIncomplete) { final CompletableFuture incomplete = new CompletableFuture(); for (int i = 0; i < cfs.length; i++) { - final CompletableFuture cf = cfs[i]; + final CompletionStage cf = cfs[i]; successOrBeIncomplete[i] = cf.handle((v, ex) -> ex == null ? cf : incomplete) - .thenCompose(Function.identity()); + .thenCompose(Function.identity()).toCompletableFuture(); failedOrBeIncomplete[i] = cf.handle((v, ex) -> ex == null ? incomplete : cf) - .thenCompose(Function.identity()); + .thenCompose(Function.identity()).toCompletableFuture(); } } @@ -195,14 +201,14 @@ private static void fill(CompletableFuture[] cfs, * @return a new CompletableFuture that is completed with the result * or exception from any of the given CompletableFutures when one completes * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #anyOfSuccess(CompletableFuture[]) + * @see #anyOfSuccess(CompletionStage[]) * @see CompletableFuture#anyOf(CompletableFuture[]) */ @Contract(pure = true) @SafeVarargs - @SuppressWarnings("unchecked") - public static CompletableFuture anyOf(CompletableFuture... cfs) { - return (CompletableFuture) CompletableFuture.anyOf(cfs); + @SuppressWarnings({"unchecked", "rawtypes"}) + public static CompletableFuture anyOf(CompletionStage... cfs) { + return (CompletableFuture) CompletableFuture.anyOf(toCompletableFutureArray((CompletionStage[]) cfs)); } /** @@ -213,23 +219,23 @@ public static CompletableFuture anyOf(CompletableFuture... c * returns a new CompletableFuture that is already completed exceptionally * with a CompletionException holding a {@link NoCfsProvidedException} as its cause. *

- * This method is the same as {@link #anyOf(CompletableFuture[])} + * This method is the same as {@link #anyOf(CompletionStage[])} * except for the any-success behavior(not any-complete). * * @param cfs the CompletableFutures * @return a new CompletableFuture that is successful * when any of the given CompletableFutures success, with the same result * @throws NullPointerException if the array or any of its elements are {@code null} - * @see #anyOf(CompletableFuture[]) + * @see #anyOf(CompletionStage[]) */ @Contract(pure = true) @SafeVarargs @SuppressWarnings({"unchecked", "rawtypes"}) - public static CompletableFuture anyOfSuccess(CompletableFuture... cfs) { + public static CompletableFuture anyOfSuccess(CompletionStage... cfs) { requireCfsAndEleNonNull(cfs); final int size = cfs.length; if (size == 0) return failedFuture(new NoCfsProvidedException()); - if (size == 1) return (CompletableFuture) copy(cfs[0]); + if (size == 1) return (CompletableFuture) copy(cfs[0].toCompletableFuture()); // NOTE: fill ONE MORE element of successOrBeIncompleteCfs LATER final CompletableFuture[] successOrBeIncomplete = new CompletableFuture[size + 1]; @@ -254,19 +260,19 @@ public static CompletableFuture anyOfSuccess(CompletableFuture CompletableFuture> allTupleOf( - CompletableFuture cf1, CompletableFuture cf2) { + CompletionStage cf1, CompletionStage cf2) { requireCfsAndEleNonNull(cf1, cf2); final Object[] result = new Object[2]; return CompletableFuture.allOf( - cf1.thenAccept(t1 -> result[0] = t1), - cf2.thenAccept(t2 -> result[1] = t2) + cf1.thenAccept(t1 -> result[0] = t1).toCompletableFuture(), + cf2.thenAccept(t2 -> result[1] = t2).toCompletableFuture() ).thenApply(unused -> Tuple2.of((T1) result[0], (T2) result[1]) ); @@ -278,18 +284,18 @@ public static CompletableFuture> allTupleOf( * CompletableFuture also does so *without* waiting other incomplete given CompletableFutures, * with a CompletionException holding this exception as its cause. *

- * This method is the same as {@link #allTupleOf(CompletableFuture, CompletableFuture)} + * This method is the same as {@link #allTupleOf(CompletionStage, CompletionStage)} * except for the fast-fail behavior. * * @return a new CompletableFuture that is successful when the given two CompletableFutures success * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see #allOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) @SuppressWarnings("unchecked") public static CompletableFuture> allTupleOfFastFail( - CompletableFuture cf1, CompletableFuture cf2) { + CompletionStage cf1, CompletionStage cf2) { requireCfsAndEleNonNull(cf1, cf2); final Object[] result = new Object[2]; @@ -308,20 +314,20 @@ public static CompletableFuture> allTupleOfFastFail( * * @return a new CompletableFuture that is completed when the given 3 CompletableFutures complete * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see #allResultsOf(CompletableFuture[]) + * @see #allResultsOf(CompletionStage[]) * @see CompletableFuture#allOf(CompletableFuture[]) */ @Contract(pure = true) @SuppressWarnings("unchecked") public static CompletableFuture> allTupleOf( - CompletableFuture cf1, CompletableFuture cf2, CompletableFuture cf3) { + CompletionStage cf1, CompletionStage cf2, CompletionStage cf3) { requireCfsAndEleNonNull(cf1, cf2, cf3); final Object[] result = new Object[3]; return CompletableFuture.allOf( - cf1.thenAccept(t1 -> result[0] = t1), - cf2.thenAccept(t2 -> result[1] = t2), - cf3.thenAccept(t3 -> result[2] = t3) + cf1.thenAccept(t1 -> result[0] = t1).toCompletableFuture(), + cf2.thenAccept(t2 -> result[1] = t2).toCompletableFuture(), + cf3.thenAccept(t3 -> result[2] = t3).toCompletableFuture() ).thenApply(unused -> Tuple3.of((T1) result[0], (T2) result[1], (T3) result[2]) ); @@ -333,18 +339,18 @@ public static CompletableFuture> allTupleOf( * CompletableFuture also does so *without* waiting other incomplete given CompletableFutures, * with a CompletionException holding this exception as its cause. *

- * This method is the same as {@link #allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture)} + * This method is the same as {@link #allTupleOf(CompletionStage, CompletionStage, CompletionStage)} * except for the fast-fail behavior. * * @return a new CompletableFuture that is successful when the given three CompletableFutures success * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see #allOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) @SuppressWarnings("unchecked") public static CompletableFuture> allTupleOfFastFail( - CompletableFuture cf1, CompletableFuture cf2, CompletableFuture cf3) { + CompletionStage cf1, CompletionStage cf2, CompletionStage cf3) { requireCfsAndEleNonNull(cf1, cf2, cf3); final Object[] result = new Object[3]; @@ -364,22 +370,22 @@ public static CompletableFuture> allTupleOfFastF * * @return a new CompletableFuture that is completed when the given 4 CompletableFutures complete * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see #allResultsOf(CompletableFuture[]) + * @see #allResultsOf(CompletionStage[]) * @see CompletableFuture#allOf(CompletableFuture[]) */ @Contract(pure = true) @SuppressWarnings("unchecked") public static CompletableFuture> allTupleOf( - CompletableFuture cf1, CompletableFuture cf2, - CompletableFuture cf3, CompletableFuture cf4) { + CompletionStage cf1, CompletionStage cf2, + CompletionStage cf3, CompletionStage cf4) { requireCfsAndEleNonNull(cf1, cf2, cf3, cf4); final Object[] result = new Object[4]; return CompletableFuture.allOf( - cf1.thenAccept(t1 -> result[0] = t1), - cf2.thenAccept(t2 -> result[1] = t2), - cf3.thenAccept(t3 -> result[2] = t3), - cf4.thenAccept(t4 -> result[3] = t4) + cf1.thenAccept(t1 -> result[0] = t1).toCompletableFuture(), + cf2.thenAccept(t2 -> result[1] = t2).toCompletableFuture(), + cf3.thenAccept(t3 -> result[2] = t3).toCompletableFuture(), + cf4.thenAccept(t4 -> result[3] = t4).toCompletableFuture() ).thenApply(unused -> Tuple4.of((T1) result[0], (T2) result[1], (T3) result[2], (T4) result[3]) ); @@ -391,19 +397,19 @@ public static CompletableFuture> allTupl * CompletableFuture also does so *without* waiting other incomplete given CompletableFutures, * with a CompletionException holding this exception as its cause. *

- * This method is the same as {@link #allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture)} + * This method is the same as {@link #allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage)} * except for the fast-fail behavior. * * @return a new CompletableFuture that is successful when the given 4 CompletableFutures success * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see #allOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) @SuppressWarnings("unchecked") public static CompletableFuture> allTupleOfFastFail( - CompletableFuture cf1, CompletableFuture cf2, - CompletableFuture cf3, CompletableFuture cf4) { + CompletionStage cf1, CompletionStage cf2, + CompletionStage cf3, CompletionStage cf4) { requireCfsAndEleNonNull(cf1, cf2, cf3, cf4); final Object[] result = new Object[4]; @@ -424,23 +430,23 @@ public static CompletableFuture> allTupl * * @return a new CompletableFuture that is completed when the given 5 CompletableFutures complete * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see #allResultsOf(CompletableFuture[]) + * @see #allResultsOf(CompletionStage[]) * @see CompletableFuture#allOf(CompletableFuture[]) */ @Contract(pure = true) @SuppressWarnings("unchecked") public static CompletableFuture> allTupleOf( - CompletableFuture cf1, CompletableFuture cf2, - CompletableFuture cf3, CompletableFuture cf4, CompletableFuture cf5) { + CompletionStage cf1, CompletionStage cf2, + CompletionStage cf3, CompletionStage cf4, CompletionStage cf5) { requireCfsAndEleNonNull(cf1, cf2, cf3, cf4, cf5); final Object[] result = new Object[5]; return CompletableFuture.allOf( - cf1.thenAccept(t1 -> result[0] = t1), - cf2.thenAccept(t2 -> result[1] = t2), - cf3.thenAccept(t3 -> result[2] = t3), - cf4.thenAccept(t4 -> result[3] = t4), - cf5.thenAccept(t5 -> result[4] = t5) + cf1.thenAccept(t1 -> result[0] = t1).toCompletableFuture(), + cf2.thenAccept(t2 -> result[1] = t2).toCompletableFuture(), + cf3.thenAccept(t3 -> result[2] = t3).toCompletableFuture(), + cf4.thenAccept(t4 -> result[3] = t4).toCompletableFuture(), + cf5.thenAccept(t5 -> result[4] = t5).toCompletableFuture() ).thenApply(unused -> Tuple5.of((T1) result[0], (T2) result[1], (T3) result[2], (T4) result[3], (T5) result[4]) ); @@ -452,19 +458,19 @@ public static CompletableFuture> * CompletableFuture also does so *without* waiting other incomplete given CompletableFutures, * with a CompletionException holding this exception as its cause. *

- * This method is the same as {@link #allTupleOf(CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture, CompletableFuture)} + * This method is the same as {@link #allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage)} * except for the fast-fail behavior. * * @return a new CompletableFuture that is successful when the given 5 CompletableFutures success * @throws NullPointerException if any of the given CompletableFutures are {@code null} - * @see #allResultsOfFastFail(CompletableFuture[]) - * @see #allOfFastFail(CompletableFuture[]) + * @see #allResultsOfFastFail(CompletionStage[]) + * @see #allOfFastFail(CompletionStage[]) */ @Contract(pure = true) @SuppressWarnings("unchecked") public static CompletableFuture> allTupleOfFastFail( - CompletableFuture cf1, CompletableFuture cf2, - CompletableFuture cf3, CompletableFuture cf4, CompletableFuture cf5) { + CompletionStage cf1, CompletionStage cf2, + CompletionStage cf3, CompletionStage cf4, CompletionStage cf5) { requireCfsAndEleNonNull(cf1, cf2, cf3, cf4, cf5); final Object[] result = new Object[5]; diff --git a/cffu-core/src/main/java/io/foldright/cffu/NoCfsProvidedException.java b/cffu-core/src/main/java/io/foldright/cffu/NoCfsProvidedException.java index 613d4fb4..975235ac 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/NoCfsProvidedException.java +++ b/cffu-core/src/main/java/io/foldright/cffu/NoCfsProvidedException.java @@ -1,15 +1,15 @@ package io.foldright.cffu; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; /** * Exception indicates that NO cfs({@link Cffu} / {@link CompletableFuture}) are provided * for methods require cf arguments. * - * @see CffuFactory#anyOfSuccess(Cffu[]) - * @see CffuFactory#anyOfSuccess(CompletableFuture[]) - * @see CompletableFutureUtils#anyOfSuccess(CompletableFuture[]) + * @see CffuFactory#anyOfSuccess(CompletionStage[]) + * @see CompletableFutureUtils#anyOfSuccess(CompletionStage[]) */ @SuppressWarnings("serial") public class NoCfsProvidedException extends RuntimeException { diff --git a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt index aa8ed1f2..83e34499 100644 --- a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt +++ b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt @@ -47,8 +47,8 @@ import java.util.function.Function * @see allResultsOfCompletableFuture * @see CompletableFuture.allOf */ -fun Collection>.allOfCompletableFuture(): CompletableFuture = - CompletableFuture.allOf(*this.toTypedArray()) +fun Collection>.allOfCompletableFuture(): CompletableFuture = + CompletableFuture.allOf(*this.map { it.toCompletableFuture() }.toTypedArray()) /** * Returns a new CompletableFuture that is completed when all the given CompletableFutures complete. @@ -69,8 +69,10 @@ fun Collection>.allOfCompletableFuture(): CompletableFuture * @see allResultsOfCompletableFuture * @see CompletableFuture.allOf */ -fun Array>.allOfCompletableFuture(): CompletableFuture = - CompletableFuture.allOf(*this) +@Suppress("UNCHECKED_CAST") +fun Array>.allOfCompletableFuture(): CompletableFuture = + CompletableFuture.allOf(*(this as Array>).toCompletableFuture()) + /** * Returns a new CompletableFuture that is successful when all the given CompletableFutures success, @@ -89,7 +91,7 @@ fun Array>.allOfCompletableFuture(): CompletableFuture< * @see allResultsOfFastFailCompletableFuture * @see CompletableFutureUtils.allOfFastFail */ -fun Collection>.allOfFastFailCompletableFuture(): CompletableFuture = +fun Collection>.allOfFastFailCompletableFuture(): CompletableFuture = CompletableFutureUtils.allOfFastFail(*this.toTypedArray()) /** @@ -109,7 +111,7 @@ fun Collection>.allOfFastFailCompletableFuture(): Completab * @see allResultsOfFastFailCompletableFuture * @see CompletableFutureUtils.allOfFastFail */ -fun Array>.allOfFastFailCompletableFuture(): CompletableFuture = +fun Array>.allOfFastFailCompletableFuture(): CompletableFuture = CompletableFutureUtils.allOfFastFail(*this) /** @@ -128,7 +130,7 @@ fun Array>.allOfFastFailCompletableFuture(): Completabl * @see allResultsOfCffu * @see allOfCompletableFuture */ -fun Collection>.allResultsOfCompletableFuture(): CompletableFuture> = +fun Collection>.allResultsOfCompletableFuture(): CompletableFuture> = CompletableFutureUtils.allResultsOf(*this.toTypedArray()) /** @@ -147,7 +149,7 @@ fun Collection>.allResultsOfCompletableFuture(): Co * @see allResultsOfCffu * @see allOfCompletableFuture */ -fun Array>.allResultsOfCompletableFuture(): CompletableFuture> = +fun Array>.allResultsOfCompletableFuture(): CompletableFuture> = CompletableFutureUtils.allResultsOf(*this) /** @@ -167,7 +169,7 @@ fun Array>.allResultsOfCompletableFuture(): Com * @see allResultsOfFastFailCffu * @see allOfFastFailCompletableFuture */ -fun Collection>.allResultsOfFastFailCompletableFuture(): CompletableFuture> = +fun Collection>.allResultsOfFastFailCompletableFuture(): CompletableFuture> = CompletableFutureUtils.allResultsOfFastFail(*this.toTypedArray()) /** @@ -187,7 +189,7 @@ fun Collection>.allResultsOfFastFailCompletableFutu * @see allResultsOfFastFailCffu * @see allOfFastFailCompletableFuture */ -fun Array>.allResultsOfFastFailCompletableFuture(): CompletableFuture> = +fun Array>.allResultsOfFastFailCompletableFuture(): CompletableFuture> = CompletableFutureUtils.allResultsOfFastFail(*this) //////////////////////////////////////// @@ -208,7 +210,7 @@ fun Array>.allResultsOfFastFailCompletableFutur * * @see anyOfCffu */ -fun Collection>.anyOfCompletableFuture(): CompletableFuture = +fun Collection>.anyOfCompletableFuture(): CompletableFuture = CompletableFutureUtils.anyOf(*this.toTypedArray()) /** @@ -222,7 +224,7 @@ fun Collection>.anyOfCompletableFuture(): Completab * * @see anyOfCffu */ -fun Array>.anyOfCompletableFuture(): CompletableFuture = +fun Array>.anyOfCompletableFuture(): CompletableFuture = CompletableFutureUtils.anyOf(*this) /** @@ -239,7 +241,7 @@ fun Array>.anyOfCompletableFuture(): Completabl * @see anyOfCompletableFuture * @see CompletableFutureUtils.anyOfSuccess */ -fun Collection>.anyOfSuccessCompletableFuture(): CompletableFuture = +fun Collection>.anyOfSuccessCompletableFuture(): CompletableFuture = CompletableFutureUtils.anyOfSuccess(*this.toTypedArray()) /** @@ -256,7 +258,7 @@ fun Collection>.anyOfSuccessCompletableFuture(): Co * @see anyOfCompletableFuture * @see CompletableFutureUtils.anyOfSuccess */ -fun Array>.anyOfSuccessCompletableFuture(): CompletableFuture = +fun Array>.anyOfSuccessCompletableFuture(): CompletableFuture = CompletableFutureUtils.anyOfSuccess(*this) //////////////////////////////////////////////////////////////////////////////// @@ -446,7 +448,7 @@ fun CompletionStage.thenCombineFastFailAsync( * @see allResultsOfCompletableFuture * @see CompletableFuture.allOf */ -fun CompletableFuture.allTupleOf(cf2: CompletableFuture): CompletableFuture> = +fun CompletionStage.allTupleOf(cf2: CompletionStage): CompletableFuture> = CompletableFutureUtils.allTupleOf(this, cf2) /** @@ -461,7 +463,7 @@ fun CompletableFuture.allTupleOf(cf2: CompletableFuture): Compl * @see allResultsOfFastFailCompletableFuture * @see CompletableFutureUtils.allOfFastFail */ -fun CompletableFuture.allTupleOfFastFail(cf2: CompletableFuture): CompletableFuture> = +fun CompletionStage.allTupleOfFastFail(cf2: CompletionStage): CompletableFuture> = CompletableFutureUtils.allTupleOfFastFail(this, cf2) /** @@ -475,8 +477,8 @@ fun CompletableFuture.allTupleOfFastFail(cf2: CompletableFuture * @see allResultsOfCompletableFuture * @see CompletableFuture.allOf */ -fun CompletableFuture.allTupleOf( - cf2: CompletableFuture, cf3: CompletableFuture +fun CompletionStage.allTupleOf( + cf2: CompletionStage, cf3: CompletionStage ): CompletableFuture> = CompletableFutureUtils.allTupleOf(this, cf2, cf3) @@ -492,8 +494,8 @@ fun CompletableFuture.allTupleOf( * @see allResultsOfFastFailCompletableFuture * @see CompletableFutureUtils.allOfFastFail */ -fun CompletableFuture.allTupleOfFastFail( - cf2: CompletableFuture, cf3: CompletableFuture +fun CompletionStage.allTupleOfFastFail( + cf2: CompletionStage, cf3: CompletionStage ): CompletableFuture> = CompletableFutureUtils.allTupleOfFastFail(this, cf2, cf3) @@ -508,8 +510,8 @@ fun CompletableFuture.allTupleOfFastFail( * @see allResultsOfCompletableFuture * @see CompletableFuture.allOf */ -fun CompletableFuture.allTupleOf( - cf2: CompletableFuture, cf3: CompletableFuture, cf4: CompletableFuture +fun CompletionStage.allTupleOf( + cf2: CompletionStage, cf3: CompletionStage, cf4: CompletionStage ): CompletableFuture> = CompletableFutureUtils.allTupleOf(this, cf2, cf3, cf4) @@ -525,8 +527,8 @@ fun CompletableFuture.allTupleOf( * @see allResultsOfFastFailCompletableFuture * @see CompletableFutureUtils.allOfFastFail */ -fun CompletableFuture.allTupleOfFastFail( - cf2: CompletableFuture, cf3: CompletableFuture, cf4: CompletableFuture +fun CompletionStage.allTupleOfFastFail( + cf2: CompletionStage, cf3: CompletionStage, cf4: CompletionStage ): CompletableFuture> = CompletableFutureUtils.allTupleOfFastFail(this, cf2, cf3, cf4) @@ -541,9 +543,9 @@ fun CompletableFuture.allTupleOfFastFail( * @see allResultsOfCompletableFuture * @see CompletableFuture.allOf */ -fun CompletableFuture.allTupleOf( - cf2: CompletableFuture, cf3: CompletableFuture, - cf4: CompletableFuture, cf5: CompletableFuture +fun CompletionStage.allTupleOf( + cf2: CompletionStage, cf3: CompletionStage, + cf4: CompletionStage, cf5: CompletionStage ): CompletableFuture> = CompletableFutureUtils.allTupleOf(this, cf2, cf3, cf4, cf5) @@ -559,9 +561,9 @@ fun CompletableFuture.allTupleOf( * @see allResultsOfFastFailCompletableFuture * @see CompletableFutureUtils.allOfFastFail */ -fun CompletableFuture.allTupleOfFastFail( - cf2: CompletableFuture, cf3: CompletableFuture, - cf4: CompletableFuture, cf5: CompletableFuture +fun CompletionStage.allTupleOfFastFail( + cf2: CompletionStage, cf3: CompletionStage, + cf4: CompletionStage, cf5: CompletionStage ): CompletableFuture> = CompletableFutureUtils.allTupleOfFastFail(this, cf2, cf3, cf4, cf5)