From 279fe8bd36947944e990b2302ca2716ca079dd78 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sun, 16 Jun 2024 13:29:00 +0800 Subject: [PATCH] WIP --- .../cffu/CompletableFutureUtils.java | 30 +++++++++---------- .../cffu/CompletableFutureUtilsTest.java | 24 +++++++-------- .../kotlin/CompletableFutureExtensions.kt | 4 +-- 3 files changed, 29 insertions(+), 29 deletions(-) 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 7563e58a..5d5e7ae8 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -215,7 +215,7 @@ public static CompletableFuture> mSupplyFastFailAsync( * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @param suppliers the suppliers returning the value to be used to complete the returned CompletableFuture * @return the new CompletableFuture - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see CompletableFuture#supplyAsync(Supplier) */ @SafeVarargs @@ -289,7 +289,7 @@ private static CompletableFuture[] wrapSuppliers( *

* If you need the successful results of given stages in the given time, prefer below methods: *

    - *
  • {@link #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[])} + *
  • {@link #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[])} *
  • {@link #mostResultsOfSuccess(Object, Executor, long, TimeUnit, CompletionStage[])} *
  • {@link #mostTupleOfSuccess(long, TimeUnit, CompletionStage, CompletionStage)} *
  • {@link #mostTupleOfSuccess(Executor, long, TimeUnit, CompletionStage, CompletionStage)} @@ -303,7 +303,7 @@ private static CompletableFuture[] wrapSuppliers( * @see #allResultsOf(CompletionStage[]) * @see #allTupleOf(CompletionStage, CompletionStage) * @see #allTupleOf(CompletionStage, CompletionStage, CompletionStage, CompletionStage, CompletionStage) - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #mostResultsOfSuccess(Object, Executor, long, TimeUnit, CompletionStage[]) * @see #mostTupleOfSuccess(long, TimeUnit, CompletionStage, CompletionStage) * @see #mostTupleOfSuccess(Executor, long, TimeUnit, CompletionStage, CompletionStage) @@ -375,7 +375,7 @@ public static CompletableFuture> allResultsOf(CompletionStage * If you need the successful results of given stages in the given time, prefer below methods: *
      - *
    • {@link #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[])} + *
    • {@link #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[])} *
    • {@link #mostResultsOfSuccess(Object, Executor, long, TimeUnit, CompletionStage[])} *
    • {@link #mostTupleOfSuccess(long, TimeUnit, CompletionStage, CompletionStage)} *
    • {@link #mostTupleOfSuccess(Executor, long, TimeUnit, CompletionStage, CompletionStage)} @@ -389,7 +389,7 @@ public static CompletableFuture> allResultsOf(CompletionStage CompletableFuture> allResultsOfFastFail(CompletionStag *

      * If the given stage is successful, its result is the completed value; Otherwise the given valueIfNotSuccess. * + * @param valueIfNotSuccess the value to return if not completed successfully * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter - * @param valueIfNotSuccess the value to return if not completed successfully * @param cfs the stages * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) @SafeVarargs public static CompletableFuture> mostResultsOfSuccess( - long timeout, TimeUnit unit, @Nullable T valueIfNotSuccess, CompletionStage... cfs) { + @Nullable T valueIfNotSuccess, long timeout, TimeUnit unit, CompletionStage... cfs) { return mostResultsOfSuccess(valueIfNotSuccess, AsyncPoolHolder.ASYNC_POOL, timeout, unit, cfs); } @@ -900,7 +900,7 @@ private static T tupleOf0(Object... elements) { * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @return a new CompletableFuture that is completed when the given two stages complete - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) @@ -919,7 +919,7 @@ public static CompletableFuture> mostTupleOfSuccess( * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @return a new CompletableFuture that is completed when the given two stages complete - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) @@ -938,7 +938,7 @@ public static CompletableFuture> mostTupleOfSuccess( * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @return a new CompletableFuture that is completed when the given three stages complete - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) @@ -958,7 +958,7 @@ public static CompletableFuture> mostTupleOfSucc * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @return a new CompletableFuture that is completed when the given three stages complete - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) @@ -977,7 +977,7 @@ public static CompletableFuture> mostTupleOfSucc * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @return a new CompletableFuture that is completed when the given four stages complete - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) @@ -998,7 +998,7 @@ public static CompletableFuture> mostTup * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @return a new CompletableFuture that is completed when the given four stages complete - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) @@ -1018,7 +1018,7 @@ public static CompletableFuture> mostTup * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @return a new CompletableFuture that is completed when the given five stages complete - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) @@ -1039,7 +1039,7 @@ public static CompletableFuture> * @param timeout how long to wait in units of {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter * @return a new CompletableFuture that is completed when the given five stages complete - * @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[]) + * @see #mostResultsOfSuccess(Object, long, TimeUnit, CompletionStage[]) * @see #getSuccessNow(CompletableFuture, Object) */ @Contract(pure = true) diff --git a/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java b/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java index 572d5235..69c97a0c 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java @@ -392,36 +392,36 @@ void test_mostOf() throws Exception { final CompletableFuture incomplete = createIncompleteFuture(); // 0 input cf - assertEquals(0, mostResultsOfSuccess(10, TimeUnit.MILLISECONDS, null).get().size()); + assertEquals(0, mostResultsOfSuccess(null, 10, TimeUnit.MILLISECONDS).get().size()); // 1 input cf assertEquals(Collections.singletonList(n), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, null, completed).get()); + null, 10, TimeUnit.MILLISECONDS, completed).get()); assertEquals(Collections.singletonList(n), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, anotherN, completedStage).get()); + anotherN, 10, TimeUnit.MILLISECONDS, completedStage).get()); assertEquals(Collections.singletonList(anotherN), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, anotherN, failed).get()); + anotherN, 10, TimeUnit.MILLISECONDS, failed).get()); assertEquals(Collections.singletonList(anotherN), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, anotherN, cancelled).get()); + anotherN, 10, TimeUnit.MILLISECONDS, cancelled).get()); assertEquals(Collections.singletonList(anotherN), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, anotherN, incomplete).get()); + anotherN, 10, TimeUnit.MILLISECONDS, incomplete).get()); // more input cf assertEquals(Arrays.asList(n, null, null, null), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, null, completed, failed, cancelled, incomplete + null, 10, TimeUnit.MILLISECONDS, completed, failed, cancelled, incomplete ).get()); assertEquals(Arrays.asList(n, anotherN, anotherN, anotherN), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, anotherN, completedStage, failed, cancelled, incomplete + anotherN, 10, TimeUnit.MILLISECONDS, completedStage, failed, cancelled, incomplete ).get()); assertEquals(Arrays.asList(anotherN, anotherN, anotherN), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, anotherN, failed, cancelled, incomplete + anotherN, 10, TimeUnit.MILLISECONDS, failed, cancelled, incomplete ).get()); // do not wait for failed and cancelled assertEquals(Arrays.asList(anotherN, anotherN), mostResultsOfSuccess( - 10, TimeUnit.DAYS, anotherN, failed, cancelled + anotherN, 10, TimeUnit.DAYS, failed, cancelled ).get()); } @@ -431,10 +431,10 @@ void test_mostOf_wontModifyInputCf() throws Exception { final CompletableFuture incomplete2 = createIncompleteFuture(); assertEquals(Collections.singletonList(null), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, null, incomplete + null, 10, TimeUnit.MILLISECONDS, incomplete ).get()); assertEquals(Arrays.asList(null, null), mostResultsOfSuccess( - 10, TimeUnit.MILLISECONDS, null, incomplete, incomplete2 + null, 10, TimeUnit.MILLISECONDS, incomplete, incomplete2 ).get()); assertEquals(CffuState.RUNNING, state(incomplete)); 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 61480a72..5d165956 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 @@ -192,7 +192,7 @@ fun Array>.allResultsOfFastFailCompletableFuture( fun Collection>.mostResultsOfSuccessCompletableFuture( timeout: Long, unit: TimeUnit, valueIfNotSuccess: T ): CompletableFuture> = - CompletableFutureUtils.mostResultsOfSuccess(timeout, unit, valueIfNotSuccess, *toTypedArray()) + CompletableFutureUtils.mostResultsOfSuccess(valueIfNotSuccess, timeout, unit, *toTypedArray()) /** * Returns a new CompletableFuture with the most results in the **same order** of @@ -208,7 +208,7 @@ fun Collection>.mostResultsOfSuccessCompletableFuture fun Array>.mostResultsOfSuccessCompletableFuture( timeout: Long, unit: TimeUnit, valueIfNotSuccess: T ): CompletableFuture> = - CompletableFutureUtils.mostResultsOfSuccess(timeout, unit, valueIfNotSuccess, *this) + CompletableFutureUtils.mostResultsOfSuccess(valueIfNotSuccess, timeout, unit, *this) /** * Returns a new CompletableFuture with the most results in the **same order** of