From 644e70a86d5d5f0456425b6e11016369c159d308 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 20 Apr 2024 21:32:14 +0800 Subject: [PATCH] refactor: rename methods of `CompletableFutureUtils`, remove prefix `cffu` --- .../src/main/java/io/foldright/cffu/Cffu.java | 10 +++++----- .../main/java/io/foldright/cffu/CffuState.java | 2 +- .../foldright/cffu/CompletableFutureUtils.java | 6 +++--- .../test/java/io/foldright/cffu/CffuTest.java | 2 +- .../cffu/CompletableFutureUtilsTest.java | 16 ++++++++-------- .../cffu/kotlin/CompletableFutureExtensions.kt | 6 +++--- 6 files changed, 21 insertions(+), 21 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 b5cb611e..d5a8bca7 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java +++ b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java @@ -1235,7 +1235,7 @@ public Cffu handleAsync( // - get() // BLOCKING! // - get(timeout, unit) // BLOCKING! // - join() // BLOCKING! - // - cffuJoin(timeout, unit) // BLOCKING! + // - join(timeout, unit) // BLOCKING! // - getNow(T valueIfAbsent) // - resultNow() // - exceptionNow() @@ -1244,7 +1244,7 @@ public Cffu handleAsync( // - isCompletedExceptionally() // - isCancelled() // - state() - // - cffuState() + // - state() // // NOTE about ExecutionException or CompletionException when the computation threw an exception: // - get methods throw ExecutionException(checked exception) @@ -1333,7 +1333,7 @@ public T join() { * NOTE:
* call this method *

- * {@code result = cffu.cffuJoin(timeout, unit);} + * {@code result = cffu.join(timeout, unit);} *

* is same as: * @@ -1366,7 +1366,7 @@ public T join() { public T cffuJoin(long timeout, TimeUnit unit) { checkMinimalStage(); - return CompletableFutureUtils.cffuJoin(cf, timeout, unit); + return CompletableFutureUtils.join(cf, timeout, unit); } /** @@ -1514,7 +1514,7 @@ public Future.State state() { public CffuState cffuState() { checkMinimalStage(); - return CompletableFutureUtils.cffuState(cf); + return CompletableFutureUtils.state(cf); } //////////////////////////////////////////////////////////////////////////////// diff --git a/cffu-core/src/main/java/io/foldright/cffu/CffuState.java b/cffu-core/src/main/java/io/foldright/cffu/CffuState.java index 526345ae..81cac433 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuState.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuState.java @@ -12,7 +12,7 @@ /** * Same as {@link Future.State}, existed for - * java version compatibility({@link Cffu#cffuState cffuState} to {@link Future#state()}). + * java version compatibility({@link Cffu#cffuState state} to {@link Future#state()}). * * @author Jerry Lee (oldratlee at gmail dot com) * @see Future.State 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 d1bede14..84abfad2 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -744,7 +744,7 @@ public static CompletableFuture exceptionallyComposeAsync( * NOTE:
* call this method *

- * {@code result = CompletableFutureUtils.cffuJoin(cf, timeout, unit);} + * {@code result = CompletableFutureUtils.join(cf, timeout, unit);} *

* is same as: * @@ -769,7 +769,7 @@ public static CompletableFuture exceptionallyComposeAsync( */ @Blocking @Nullable - public static T cffuJoin(CompletableFuture cf, long timeout, TimeUnit unit) { + public static T join(CompletableFuture cf, long timeout, TimeUnit unit) { if (cf.isDone()) return cf.join(); return orTimeout(copy(cf), timeout, unit).join(); @@ -865,7 +865,7 @@ public static Throwable exceptionNow(CompletableFuture cf) { * @see Future.State */ @Contract(pure = true) - public static CffuState cffuState(CompletableFuture cf) { + public static CffuState state(CompletableFuture cf) { if (IS_JAVA19_PLUS) { return CffuState.toCffuState(cf.state()); } diff --git a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java index 0201cfbf..26514942 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java @@ -37,7 +37,7 @@ class CffuTest { // - get() // BLOCKING // - get(timeout, unit) // BLOCKING // - join() // BLOCKING - // - cffuJoin() // BLOCKING + // - join() // BLOCKING // - getNow(T valueIfAbsent) // - resultNow() // - exceptionNow() 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 4c2bfe42..60b532f9 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java @@ -738,7 +738,7 @@ void test_exceptionallyCompose() throws Exception { void test_read() { final CompletableFuture completed = completedFuture(n); - assertEquals(n, cffuJoin(completed, 1, TimeUnit.MILLISECONDS)); + assertEquals(n, join(completed, 1, TimeUnit.MILLISECONDS)); assertEquals(n, resultNow(completed)); try { exceptionNow(completed); @@ -746,14 +746,14 @@ void test_read() { } catch (IllegalStateException expected) { if (expected.getMessage() != null) assertEquals("Task completed with a result", expected.getMessage()); } - assertSame(CffuState.SUCCESS, cffuState(completed)); + assertSame(CffuState.SUCCESS, state(completed)); //////////////////////////////////////// final CompletableFuture failed = failedFuture(rte); try { - cffuJoin(failed, 1, TimeUnit.MILLISECONDS); + join(failed, 1, TimeUnit.MILLISECONDS); fail(); } catch (CompletionException expected) { assertSame(rte, expected.getCause()); @@ -765,7 +765,7 @@ void test_read() { if (expected.getMessage() != null) assertEquals("Task completed with exception", expected.getMessage()); } assertSame(rte, exceptionNow(failed)); - assertSame(CffuState.FAILED, cffuState(failed)); + assertSame(CffuState.FAILED, state(failed)); //////////////////////////////////////// @@ -782,14 +782,14 @@ void test_read() { } catch (IllegalStateException expected) { if (expected.getMessage() != null) assertEquals("Task was cancelled", expected.getMessage()); } - assertSame(CffuState.CANCELLED, cffuState(cancelled)); + assertSame(CffuState.CANCELLED, state(cancelled)); //////////////////////////////////////// final CompletableFuture incomplete = createIncompleteFuture(); try { - cffuJoin(incomplete, 1, TimeUnit.MILLISECONDS); + join(incomplete, 1, TimeUnit.MILLISECONDS); fail(); } catch (CompletionException expected) { assertTrue(expected.getCause() instanceof TimeoutException); @@ -806,11 +806,11 @@ void test_read() { } catch (IllegalStateException expected) { if (expected.getMessage() != null) assertEquals("Task has not completed", expected.getMessage()); } - assertSame(CffuState.RUNNING, cffuState(incomplete)); + assertSame(CffuState.RUNNING, state(incomplete)); // Incomplete Future -> join before timeout CompletableFuture later = createFutureCompleteLater(n); - assertEquals(n, cffuJoin(later, 3, TimeUnit.SECONDS)); + assertEquals(n, join(later, 3, TimeUnit.SECONDS)); } @Test 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 05cfb044..4cedf695 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 @@ -565,7 +565,7 @@ fun CompletableFuture.cffuExceptionallyComposeAsync( * NOTE:
* call this method * - * `result = CompletableFutureUtils.cffuJoin(cf, timeout, unit);` + * `result = CompletableFutureUtils.join(cf, timeout, unit);` * * is same as: * @@ -588,7 +588,7 @@ fun CompletableFuture.cffuExceptionallyComposeAsync( */ @Suppress("UNCHECKED_CAST") fun CompletableFuture.cffuJoin(timeout: Long, unit: TimeUnit): T = - CompletableFutureUtils.cffuJoin(this, timeout, unit) as T + CompletableFutureUtils.join(this, timeout, unit) as T /** * Returns the computed result, without waiting. @@ -631,7 +631,7 @@ fun CompletableFuture.cffuExceptionNow(): Throwable = * @see CompletableFuture.state */ fun CompletableFuture.cffuState(): CffuState = - CompletableFutureUtils.cffuState(this) + CompletableFutureUtils.state(this) //# Write methods of CompletableFuture