From 95eb0b28412166b4c6fef5d1ed8f1a07e9f65567 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 18 May 2024 19:41:26 +0800 Subject: [PATCH] refactor: rename `batchGetSuccessNow` method -> `MGetSuccessNow`; hide multi-read methods(`MGetSuccessNow`/`tupleGetSuccessNow`) from API --- .../java/io/foldright/cffu/CffuFactory.java | 2 +- .../cffu/CompletableFutureUtils.java | 36 +++++++++---------- .../cffu/CompletableFutureUtilsTest.java | 2 +- .../foldright/cffu/kotlin/CffuExtensions.kt | 8 ++--- .../kotlin/CompletableFutureExtensions.kt | 4 +-- 5 files changed, 26 insertions(+), 26 deletions(-) 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 24c4d41d..01af59e4 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -438,8 +438,8 @@ public final Cffu> allResultsOfFastFail(CompletionStage * @param valueIfNotSuccess the value to return if not completed successfully * @param cfs the stages * @see Cffu#getSuccessNow(Object) - * @see CompletableFutureUtils#batchGetSuccessNow(Object, CompletionStage[]) */ + // TODO * @see CompletableFutureUtils#MGetSuccessNow(Object, CompletionStage[]) @Contract(pure = true) @SafeVarargs public final Cffu> mostResultsOfSuccess( 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 15c8e991..313864b6 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -196,9 +196,9 @@ public static CompletableFuture> allResultsOfFastFail(CompletionStag * @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 #batchGetSuccessNow(Object, CompletionStage[]) * @see #getSuccessNow(CompletionStage, Object) */ + // * @see #MGetSuccessNow(Object, CompletionStage[]) @Contract(pure = true) @SafeVarargs public static CompletableFuture> mostResultsOfSuccess( @@ -214,7 +214,7 @@ public static CompletableFuture> mostResultsOfSuccess( final CompletableFuture[] cfArray = f_toCfArray(cfs); return orTimeout(CompletableFuture.allOf(cfArray), timeout, unit) - .handle((unused, ex) -> batchGetSuccessNow(valueIfNotSuccess, cfArray)); + .handle((unused, ex) -> MGetSuccessNow(valueIfNotSuccess, cfArray)); } @SafeVarargs @@ -1342,8 +1342,8 @@ public static T join(CompletableFuture cf, long timeout, TimeUnit unit) { * * @param valueIfNotSuccess the value to return if not completed successfully * @return the result value, if completed successfully, else the given valueIfNotSuccess - * @see #batchGetSuccessNow(Object, CompletionStage[]) */ + // * @see #MGetSuccessNow(Object, CompletionStage[]) @Contract(pure = true) @Nullable public static T getSuccessNow(CompletionStage cf, @Nullable T valueIfNotSuccess) { @@ -1468,10 +1468,10 @@ public static CffuState state(CompletableFuture cf) { } } - //# New enhanced batch read(explicitly) methods + //# New enhanced multi-read(explicitly) methods /** - * Batch gets the results in the same order of the given cfs, + * Multi-Gets(MGet) the results in the same order of the given cfs, * use the result value if the given stage is completed successfully, else use the given valueIfNotSuccess * (aka the result extraction logic is {@link #getSuccessNow(CompletionStage, Object)}). * @@ -1481,14 +1481,14 @@ public static CffuState state(CompletableFuture cf) { */ @Contract(pure = true) @SafeVarargs - public static List batchGetSuccessNow(@Nullable T valueIfNotSuccess, CompletionStage... cfs) { - return arrayList(batchGet0(cf -> getSuccessNow(cf, valueIfNotSuccess), cfs)); + static List MGetSuccessNow(@Nullable T valueIfNotSuccess, CompletionStage... cfs) { + return arrayList(MGet0(cf -> getSuccessNow(cf, valueIfNotSuccess), cfs)); } @SafeVarargs @SuppressWarnings("unchecked") - private static T[] batchGet0(Function, ? extends T> resultGetter, - CompletionStage... cfs) { + private static T[] MGet0(Function, ? extends T> resultGetter, + CompletionStage... cfs) { final CompletableFuture[] cfArray = f_toCfArray(cfs); Object[] ret = new Object[cfs.length]; for (int i = 0; i < cfArray.length; i++) { @@ -1499,49 +1499,49 @@ private static T[] batchGet0(Function, ? extends T> res } /** - * Batch gets the result value in the same order of the given cfs, + * Multi-Gets(MGet) the result value in the same order of the given cfs, * use the result value if the cf is completed successfully, else use the value {@code null} * (aka the result extraction logic is {@code getSuccessNow(cf, null)}). */ - public static Tuple2 tupleGetSuccessNow( + static Tuple2 tupleGetSuccessNow( CompletionStage cf1, CompletionStage cf2) { return tupleGet0(requireCfsAndEleNonNull(cf1, cf2)); } /** - * Batch gets the result value in the same order of the given cfs, + * Multi-Gets(MGet) the result value in the same order of the given cfs, * use the result value if the cf is completed successfully, else use the value {@code null} * (aka the result extraction logic is {@code getSuccessNow(cf, null)}). */ - public static Tuple3 tupleGetSuccessNow( + static Tuple3 tupleGetSuccessNow( CompletionStage cf1, CompletionStage cf2, CompletionStage cf3) { return tupleGet0(requireCfsAndEleNonNull(cf1, cf2, cf3)); } /** - * Batch gets the result value in the same order of the given cfs, + * Multi-Gets(MGet) the result value in the same order of the given cfs, * use the result value if the cf is completed successfully, else use the value {@code null} * (aka the result extraction logic is {@code getSuccessNow(cf, null)}). */ - public static Tuple4 tupleGetSuccessNow( + static Tuple4 tupleGetSuccessNow( CompletionStage cf1, CompletionStage cf2, CompletionStage cf3, CompletionStage cf4) { return tupleGet0(requireCfsAndEleNonNull(cf1, cf2, cf3, cf4)); } /** - * Batch gets the result value in the same order of the given cfs, + * Multi-Gets(MGet) the result value in the same order of the given cfs, * use the result value if the cf is completed successfully, else the value {@code null} * (aka the result extraction logic is {@code getSuccessNow(cf, null)}). */ - public static Tuple5 tupleGetSuccessNow( + static Tuple5 tupleGetSuccessNow( CompletionStage cf1, CompletionStage cf2, CompletionStage cf3, CompletionStage cf4, CompletionStage cf5) { return tupleGet0(requireCfsAndEleNonNull(cf1, cf2, cf3, cf4, cf5)); } private static T tupleGet0(CompletionStage... css) { - return tupleOf0(batchGet0(cf -> getSuccessNow(cf, null), css)); + return tupleOf0(MGet0(cf -> getSuccessNow(cf, null), css)); } //# Write methods of CompletableFuture 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 94d8f7bf..5f884be3 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java @@ -1020,7 +1020,7 @@ void test_gets() { final CompletableFuture incomplete = createIncompleteFuture(); assertEquals(Arrays.asList(n, anotherN, anotherN, anotherN), - batchGetSuccessNow(anotherN, completed, incomplete, cancelled, failed)); + MGetSuccessNow(anotherN, completed, incomplete, cancelled, failed)); assertEquals(Tuple2.of(n, null), tupleGetSuccessNow(completed, failed)); assertEquals(Tuple3.of(null, n, null), tupleGetSuccessNow(failed, completed, cancelled)); diff --git a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt index 6667f85d..c2e11073 100644 --- a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt +++ b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt @@ -404,8 +404,8 @@ fun Array>.allOfFastFailCffu(cffuFactory: CffuFactory): C * @param unit a `TimeUnit` determining how to interpret the `timeout` parameter * @param valueIfNotSuccess the value to return if not completed successfully * @see Cffu.getSuccessNow - * @see CompletableFutureUtils.batchGetSuccessNow */ +// * @see CompletableFutureUtils.MGetSuccessNow fun Collection>.mostResultsOfSuccessCffu( timeout: Long, unit: TimeUnit, valueIfNotSuccess: T, cffuFactory: CffuFactory = ABSENT ): Cffu> { @@ -425,8 +425,8 @@ fun Collection>.mostResultsOfSuccessCffu( * @param unit a `TimeUnit` determining how to interpret the `timeout` parameter * @param valueIfNotSuccess the value to return if not completed successfully * @see Cffu.getSuccessNow - * @see CompletableFutureUtils.batchGetSuccessNow */ +// * @see CompletableFutureUtils.MGetSuccessNow fun Array>.mostResultsOfSuccessCffu( timeout: Long, unit: TimeUnit, valueIfNotSuccess: T, cffuFactory: CffuFactory = ABSENT ): Cffu> { @@ -448,8 +448,8 @@ fun Array>.mostResultsOfSuccessCffu( * @param unit a `TimeUnit` determining how to interpret the `timeout` parameter * @param valueIfNotSuccess the value to return if not completed successfully * @see Cffu.getSuccessNow - * @see CompletableFutureUtils.batchGetSuccessNow */ +// * @see CompletableFutureUtils.MGetSuccessNow @JvmName("mostResultsOfSuccessCffuCs") fun Collection>.mostResultsOfSuccessCffu( timeout: Long, unit: TimeUnit, valueIfNotSuccess: T, cffuFactory: CffuFactory @@ -467,8 +467,8 @@ fun Collection>.mostResultsOfSuccessCffu( * @param unit a `TimeUnit` determining how to interpret the `timeout` parameter * @param valueIfNotSuccess the value to return if not completed successfully * @see Cffu.getSuccessNow - * @see CompletableFutureUtils.batchGetSuccessNow */ +// * @see CompletableFutureUtils.MGetSuccessNow fun Array>.mostResultsOfSuccessCffu( timeout: Long, unit: TimeUnit, valueIfNotSuccess: T, cffuFactory: CffuFactory ): Cffu> = 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 fb03a5c5..5d4c2940 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 @@ -218,8 +218,8 @@ fun Array>.allResultsOfFastFailCompletableFuture( * @param unit a `TimeUnit` determining how to interpret the `timeout` parameter * @param valueIfNotSuccess the value to return if not completed successfully * @see getSuccessNow - * @see CompletableFutureUtils.batchGetSuccessNow */ +// * @see CompletableFutureUtils.MGetSuccessNow fun Collection>.mostResultsOfSuccessCompletableFuture( timeout: Long, unit: TimeUnit, valueIfNotSuccess: T ): CompletableFuture> = @@ -236,8 +236,8 @@ fun Collection>.mostResultsOfSuccessCompletableFuture * @param unit a `TimeUnit` determining how to interpret the `timeout` parameter * @param valueIfNotSuccess the value to return if not completed successfully * @see getSuccessNow - * @see CompletableFutureUtils.batchGetSuccessNow */ +// * @see CompletableFutureUtils.MGetSuccessNow fun Array>.mostResultsOfSuccessCompletableFuture( timeout: Long, unit: TimeUnit, valueIfNotSuccess: T ): CompletableFuture> =