Skip to content

Commit

Permalink
format: static import Function.identity function
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Apr 28, 2024
1 parent f2af962 commit aab5220
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 34 deletions.
1 change: 0 additions & 1 deletion cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ public <U, V> Cffu<V> thenCombineAsync(CompletionStage<? extends U> other,
return reset0(cf.thenCombineAsync(other, fn, executor));
}


/**
* Returns a new Cffu that, when this and the other given stage both complete normally,
* is executed with the two results as arguments to the supplied function.
Expand Down
1 change: 0 additions & 1 deletion cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ public <T1, T2, T3, T4> Cffu<Tuple4<T1, T2, T3, T4>> allTupleOf(
return new0(CompletableFutureUtils.allTupleOf(cf1, cf2, cf3, cf4));
}


/**
* Returns a new Cffu that is successful when the given four CompletableFutures success.
* If any of the given CompletableFutures complete exceptionally, then the returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static io.foldright.cffu.CffuFactory.toCompletableFutureArray;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;


/**
Expand Down Expand Up @@ -155,7 +156,6 @@ private static void requireCfsAndEleNonNull(CompletionStage<?>... cfs) {
* Safer for application code which may reuse the returned list as normal collection.
*/
@SafeVarargs
@SuppressWarnings("unchecked")
private static <T> List<T> arrayList(T... elements) {
List<T> ret = new ArrayList<>(elements.length);
ret.addAll(Arrays.asList(elements));
Expand All @@ -176,10 +176,10 @@ private static void fill(CompletionStage[] cfs,
final CompletionStage cf = cfs[i];

successOrBeIncomplete[i] = cf.toCompletableFuture()
.handle((v, ex) -> ex == null ? cf : incomplete).thenCompose(Function.identity());
.handle((v, ex) -> ex == null ? cf : incomplete).thenCompose(identity());

failedOrBeIncomplete[i] = cf.toCompletableFuture()
.handle((v, ex) -> ex == null ? incomplete : cf).thenCompose(Function.identity());
.handle((v, ex) -> ex == null ? incomplete : cf).thenCompose(identity());
}
}

Expand Down Expand Up @@ -1147,7 +1147,7 @@ public static <T> CompletableFuture<T> exceptionallyAsync(
// below code is copied from CompletionStage#exceptionallyAsync
return cf.handle((r, ex) -> (ex == null) ? cf :
cf.<T>handleAsync((r1, ex1) -> fn.apply(ex1), executor)
).thenCompose(Function.identity());
).thenCompose(identity());
}

//# Timeout Control methods
Expand Down Expand Up @@ -1215,8 +1215,7 @@ public static <T> CompletableFuture<T> exceptionallyCompose(

requireNonNull(fn, "fn is null");
// below code is copied from CompletionStage.exceptionallyCompose
return cf.handle((r, ex) -> (ex == null) ? cf : fn.apply(ex))
.thenCompose(Function.identity());
return cf.handle((r, ex) -> (ex == null) ? cf : fn.apply(ex)).thenCompose(identity());
}

/**
Expand Down Expand Up @@ -1252,8 +1251,8 @@ public static <T> CompletableFuture<T> exceptionallyComposeAsync(
requireNonNull(executor, "executor is null");
// below code is copied from CompletionStage.exceptionallyComposeAsync
return cf.handle((r, ex) -> (ex == null) ? cf :
cf.handleAsync((r1, ex1) -> fn.apply(ex1), executor).thenCompose(Function.identity())
).thenCompose(Function.identity());
cf.handleAsync((r1, ex1) -> fn.apply(ex1), executor).thenCompose(identity())
).thenCompose(identity());
}

//# Read(explicitly) methods of CompletableFuture
Expand Down Expand Up @@ -1466,7 +1465,7 @@ public static <T> CompletionStage<T> minimalCompletionStage(CompletableFuture<T>
if (IS_JAVA9_PLUS) {
return cf.minimalCompletionStage();
}
return cf.thenApply(Function.identity());
return cf.thenApply(identity());
}

/**
Expand All @@ -1483,7 +1482,7 @@ public static <T> CompletableFuture<T> copy(CompletableFuture<T> cf) {
if (IS_JAVA9_PLUS) {
return cf.copy();
}
return cf.thenApply(Function.identity());
return cf.thenApply(identity());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static io.foldright.test_utils.TestUtils.*;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.ForkJoinPool.commonPool;
import static java.util.function.Function.identity;
import static org.junit.jupiter.api.Assertions.*;


Expand All @@ -44,7 +45,7 @@ void test_completedFuture() throws Exception {
@Test
void test_completedStage() throws Exception {
CompletionStage<Integer> stage = cffuFactory.completedStage(n);
CompletionStage<Integer> sa = stage.thenApply(Function.identity());
CompletionStage<Integer> sa = stage.thenApply(identity());

assertEquals(n, stage.toCompletableFuture().get());
assertEquals(n, sa.toCompletableFuture().get());
Expand Down Expand Up @@ -72,7 +73,7 @@ void test_failedFuture() throws Exception {
@Test
void test_failedStage() throws Exception {
CompletionStage<Integer> stage = cffuFactory.failedStage(rte);
CompletionStage<Integer> sa = stage.thenApply(Function.identity());
CompletionStage<Integer> sa = stage.thenApply(identity());
CompletionStage<Integer> se = stage.exceptionally(throwable -> n);

try {
Expand Down
8 changes: 4 additions & 4 deletions cffu-core/src/test/java/io/foldright/cffu/CffuTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder;
import static io.foldright.test_utils.TestUtils.*;
import static java.util.function.Function.identity;
import static org.junit.jupiter.api.Assertions.*;


Expand Down Expand Up @@ -123,9 +124,9 @@ void test_either_success() throws Exception {
assertNull(failed.acceptEitherSuccessAsync(cf, c).get());
assertNull(failed.acceptEitherSuccessAsync(cf, c, executorService).get());

assertEquals(n, failed.applyToEitherSuccess(cf, Function.identity()).get());
assertEquals(n, failed.applyToEitherSuccessAsync(cf, Function.identity()).get());
assertEquals(n, failed.applyToEitherSuccessAsync(cf, Function.identity(), executorService).get());
assertEquals(n, failed.applyToEitherSuccess(cf, identity()).get());
assertEquals(n, failed.applyToEitherSuccessAsync(cf, identity()).get());
assertEquals(n, failed.applyToEitherSuccessAsync(cf, identity(), executorService).get());
}

////////////////////////////////////////
Expand Down Expand Up @@ -238,7 +239,6 @@ void test_resetCffuFactory() {
assertSame(forbidObtrudeMethodsCffuFactory, cf.resetCffuFactory(forbidObtrudeMethodsCffuFactory).cffuFactory());
}


////////////////////////////////////////////////////////////////////////////////
//# Getter methods of Cffu properties
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static io.foldright.test_utils.TestUtils.*;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.ForkJoinPool.commonPool;
import static java.util.function.Function.identity;
import static org.junit.jupiter.api.Assertions.*;


Expand Down Expand Up @@ -761,9 +762,9 @@ void test_either() throws Exception {
assertNull(acceptEitherSuccessAsync(cf_n, incomplete, c).get());
assertNull(acceptEitherSuccessAsync(cf_n, incomplete, c, executorService).get());

assertEquals(n, applyToEitherSuccess(cf_n, incomplete, Function.identity()).get());
assertEquals(n, applyToEitherSuccessAsync(cf_n, incomplete, Function.identity()).get());
assertEquals(n, applyToEitherSuccessAsync(cf_n, incomplete, Function.identity(), executorService).get());
assertEquals(n, applyToEitherSuccess(cf_n, incomplete, identity()).get());
assertEquals(n, applyToEitherSuccessAsync(cf_n, incomplete, identity()).get());
assertEquals(n, applyToEitherSuccessAsync(cf_n, incomplete, identity(), executorService).get());
}

@Test
Expand All @@ -783,9 +784,9 @@ void test_either_success() throws Exception {
assertNull(acceptEitherSuccessAsync(failed, cf, c).get());
assertNull(acceptEitherSuccessAsync(failed, cf, c, executorService).get());

assertEquals(n, applyToEitherSuccess(failed, cf, Function.identity()).get());
assertEquals(n, applyToEitherSuccessAsync(failed, cf, Function.identity()).get());
assertEquals(n, applyToEitherSuccessAsync(failed, cf, Function.identity(), executorService).get());
assertEquals(n, applyToEitherSuccess(failed, cf, identity()).get());
assertEquals(n, applyToEitherSuccessAsync(failed, cf, identity()).get());
assertEquals(n, applyToEitherSuccessAsync(failed, cf, identity(), executorService).get());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ class CompletableFutureUsageShowcaseTest : FunSpec({
42
}.toCompletableFuture().await() shouldBe 42


cf.thenApply { it }.handle { _, t ->
t.shouldBeTypeOf<CompletionException>()
t.cause shouldBeSameInstanceAs rte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ fun shutdownExecutorService(vararg executors: ExecutorService) {
}
}


////////////////////////////////////////////////////////////////////////////////
// executors for kotest
////////////////////////////////////////////////////////////////////////////////


val testThreadPoolExecutor: ExecutorService =
createThreadPool("CompletableFutureUseTest_ThreadPool")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ private fun <T> Cffu<T>.shouldNotMinCffu(recursive: Boolean = false) {

if (recursive) newIncompleteFuture<T>().shouldNotMinCffu()


////////////////////////////////////////////////////////////
// Cffu specified methods
////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fun Collection<CompletionStage<*>>.allOfCompletableFuture(): CompletableFuture<V
fun Array<out CompletionStage<*>>.allOfCompletableFuture(): CompletableFuture<Void> =
CompletableFuture.allOf(*(this as Array<CompletionStage<Any>>).toCompletableFuture())


/**
* Returns a new CompletableFuture that is successful when all the given CompletableFutures success,
* the results(`CompletableFuture<Void>`) of the given CompletableFutures are not reflected in the returned CompletableFuture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ class CffuExtensionsTest : FunSpec({
).anyOfSuccessCffu(testCffuFactory).await() shouldBe 42
}


val cffuFactoryForOptional = newCffuFactoryBuilder(Executors.newCachedThreadPool()).build()
fun assertCffuFactoryForOptional(cffu: Cffu<*>) {
cffu.cffuFactory() shouldBeSameInstanceAs cffuFactoryForOptional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import java.util.function.BiConsumer
import java.util.function.Consumer
import java.util.function.Function
import java.util.function.Function.identity

class CompletableFutureExtensionsTest : FunSpec({
test("allOf*") {
Expand Down Expand Up @@ -326,9 +326,9 @@ class CompletableFutureExtensionsTest : FunSpec({
failed.acceptEitherSuccessAsync(cf, c).get().shouldBeNull()
failed.acceptEitherSuccessAsync(cf, c, testThreadPoolExecutor).get().shouldBeNull()

failed.applyToEitherSuccess(cf, Function.identity()).get() shouldBe n
failed.applyToEitherSuccessAsync(cf, Function.identity()).get() shouldBe n
failed.applyToEitherSuccessAsync(cf, Function.identity(), testThreadPoolExecutor).get() shouldBe n
failed.applyToEitherSuccess(cf, identity()).get() shouldBe n
failed.applyToEitherSuccessAsync(cf, identity()).get() shouldBe n
failed.applyToEitherSuccessAsync(cf, identity(), testThreadPoolExecutor).get() shouldBe n
}

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit aab5220

Please sign in to comment.