Skip to content

Commit

Permalink
refactor: rename methods of CompletableFutureUtils, remove prefix `…
Browse files Browse the repository at this point in the history
…cffu`
  • Loading branch information
oldratlee committed Apr 23, 2024
1 parent 0f68b51 commit 644e70a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ public <U> Cffu<U> handleAsync(
// - get() // BLOCKING!
// - get(timeout, unit) // BLOCKING!
// - join() // BLOCKING!
// - cffuJoin(timeout, unit) // BLOCKING!
// - join(timeout, unit) // BLOCKING!
// - getNow(T valueIfAbsent)
// - resultNow()
// - exceptionNow()
Expand All @@ -1244,7 +1244,7 @@ public <U> Cffu<U> handleAsync(
// - isCompletedExceptionally()
// - isCancelled()
// - state()
// - cffuState()
// - state()
//
// NOTE about ExecutionException or CompletionException when the computation threw an exception:
// - get methods throw ExecutionException(checked exception)
Expand Down Expand Up @@ -1333,7 +1333,7 @@ public T join() {
* <b><i>NOTE:<br></i></b>
* call this method
* <p>
* {@code result = cffu.cffuJoin(timeout, unit);}
* {@code result = cffu.join(timeout, unit);}
* <p>
* is same as:
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -1514,7 +1514,7 @@ public Future.State state() {
public CffuState cffuState() {
checkMinimalStage();

return CompletableFutureUtils.cffuState(cf);
return CompletableFutureUtils.state(cf);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion cffu-core/src/main/java/io/foldright/cffu/CffuState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public static <T> CompletableFuture<T> exceptionallyComposeAsync(
* <b><i>NOTE:<br></i></b>
* call this method
* <p>
* {@code result = CompletableFutureUtils.cffuJoin(cf, timeout, unit);}
* {@code result = CompletableFutureUtils.join(cf, timeout, unit);}
* <p>
* is same as:
*
Expand All @@ -769,7 +769,7 @@ public static <T> CompletableFuture<T> exceptionallyComposeAsync(
*/
@Blocking
@Nullable
public static <T> T cffuJoin(CompletableFuture<T> cf, long timeout, TimeUnit unit) {
public static <T> T join(CompletableFuture<T> cf, long timeout, TimeUnit unit) {
if (cf.isDone()) return cf.join();

return orTimeout(copy(cf), timeout, unit).join();
Expand Down Expand Up @@ -865,7 +865,7 @@ public static <T> Throwable exceptionNow(CompletableFuture<T> cf) {
* @see Future.State
*/
@Contract(pure = true)
public static <T> CffuState cffuState(CompletableFuture<T> cf) {
public static <T> CffuState state(CompletableFuture<T> cf) {
if (IS_JAVA19_PLUS) {
return CffuState.toCffuState(cf.state());
}
Expand Down
2 changes: 1 addition & 1 deletion cffu-core/src/test/java/io/foldright/cffu/CffuTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CffuTest {
// - get() // BLOCKING
// - get(timeout, unit) // BLOCKING
// - join() // BLOCKING
// - cffuJoin() // BLOCKING
// - join() // BLOCKING
// - getNow(T valueIfAbsent)
// - resultNow()
// - exceptionNow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,22 +738,22 @@ void test_exceptionallyCompose() throws Exception {
void test_read() {
final CompletableFuture<Integer> completed = completedFuture(n);

assertEquals(n, cffuJoin(completed, 1, TimeUnit.MILLISECONDS));
assertEquals(n, join(completed, 1, TimeUnit.MILLISECONDS));
assertEquals(n, resultNow(completed));
try {
exceptionNow(completed);
fail();
} 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<Object> failed = failedFuture(rte);

try {
cffuJoin(failed, 1, TimeUnit.MILLISECONDS);
join(failed, 1, TimeUnit.MILLISECONDS);
fail();
} catch (CompletionException expected) {
assertSame(rte, expected.getCause());
Expand All @@ -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));

////////////////////////////////////////

Expand All @@ -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<Object> incomplete = createIncompleteFuture();

try {
cffuJoin(incomplete, 1, TimeUnit.MILLISECONDS);
join(incomplete, 1, TimeUnit.MILLISECONDS);
fail();
} catch (CompletionException expected) {
assertTrue(expected.getCause() instanceof TimeoutException);
Expand All @@ -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<Integer> later = createFutureCompleteLater(n);
assertEquals(n, cffuJoin(later, 3, TimeUnit.SECONDS));
assertEquals(n, join(later, 3, TimeUnit.SECONDS));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ fun <T> CompletableFuture<T>.cffuExceptionallyComposeAsync(
* <b><i>NOTE:<br></i></b>
* call this method
*
* `result = CompletableFutureUtils.cffuJoin(cf, timeout, unit);`
* `result = CompletableFutureUtils.join(cf, timeout, unit);`
*
* is same as:
*
Expand All @@ -588,7 +588,7 @@ fun <T> CompletableFuture<T>.cffuExceptionallyComposeAsync(
*/
@Suppress("UNCHECKED_CAST")
fun <T> CompletableFuture<T>.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.
Expand Down Expand Up @@ -631,7 +631,7 @@ fun <T> CompletableFuture<T>.cffuExceptionNow(): Throwable =
* @see CompletableFuture.state
*/
fun <T> CompletableFuture<T>.cffuState(): CffuState =
CompletableFutureUtils.cffuState(this)
CompletableFutureUtils.state(this)

//# Write methods of CompletableFuture

Expand Down

0 comments on commit 644e70a

Please sign in to comment.