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 1f7a826e..f82b3d6c 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java +++ b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java @@ -494,7 +494,6 @@ public Cffu thenCombineAsync(CompletionStage 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. 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 8a51584c..5bd725c0 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -524,7 +524,6 @@ public Cffu> 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 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 69d94383..5cd60c74 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -18,6 +18,7 @@ import static io.foldright.cffu.CffuFactory.toCompletableFutureArray; import static java.util.Objects.requireNonNull; +import static java.util.function.Function.identity; /** @@ -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 List arrayList(T... elements) { List ret = new ArrayList<>(elements.length); ret.addAll(Arrays.asList(elements)); @@ -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()); } } @@ -1147,7 +1147,7 @@ public static CompletableFuture exceptionallyAsync( // below code is copied from CompletionStage#exceptionallyAsync return cf.handle((r, ex) -> (ex == null) ? cf : cf.handleAsync((r1, ex1) -> fn.apply(ex1), executor) - ).thenCompose(Function.identity()); + ).thenCompose(identity()); } //# Timeout Control methods @@ -1215,8 +1215,7 @@ public static CompletableFuture 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()); } /** @@ -1252,8 +1251,8 @@ public static CompletableFuture 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 @@ -1466,7 +1465,7 @@ public static CompletionStage minimalCompletionStage(CompletableFuture if (IS_JAVA9_PLUS) { return cf.minimalCompletionStage(); } - return cf.thenApply(Function.identity()); + return cf.thenApply(identity()); } /** @@ -1483,7 +1482,7 @@ public static CompletableFuture copy(CompletableFuture cf) { if (IS_JAVA9_PLUS) { return cf.copy(); } - return cf.thenApply(Function.identity()); + return cf.thenApply(identity()); } /** diff --git a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java index 98ebde99..f47ee250 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java @@ -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.*; @@ -44,7 +45,7 @@ void test_completedFuture() throws Exception { @Test void test_completedStage() throws Exception { CompletionStage stage = cffuFactory.completedStage(n); - CompletionStage sa = stage.thenApply(Function.identity()); + CompletionStage sa = stage.thenApply(identity()); assertEquals(n, stage.toCompletableFuture().get()); assertEquals(n, sa.toCompletableFuture().get()); @@ -72,7 +73,7 @@ void test_failedFuture() throws Exception { @Test void test_failedStage() throws Exception { CompletionStage stage = cffuFactory.failedStage(rte); - CompletionStage sa = stage.thenApply(Function.identity()); + CompletionStage sa = stage.thenApply(identity()); CompletionStage se = stage.exceptionally(throwable -> n); try { 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 8d7c3127..56c093c5 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java @@ -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.*; @@ -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()); } //////////////////////////////////////// @@ -238,7 +239,6 @@ void test_resetCffuFactory() { assertSame(forbidObtrudeMethodsCffuFactory, cf.resetCffuFactory(forbidObtrudeMethodsCffuFactory).cffuFactory()); } - //////////////////////////////////////////////////////////////////////////////// //# Getter methods of Cffu properties // 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 e57614e9..3a1b5e90 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java @@ -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.*; @@ -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 @@ -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()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/cffu-core/src/test/java/io/foldright/showcases/CompletableFutureUsageShowcaseTest.kt b/cffu-core/src/test/java/io/foldright/showcases/CompletableFutureUsageShowcaseTest.kt index c4d17d5f..d8597be6 100644 --- a/cffu-core/src/test/java/io/foldright/showcases/CompletableFutureUsageShowcaseTest.kt +++ b/cffu-core/src/test/java/io/foldright/showcases/CompletableFutureUsageShowcaseTest.kt @@ -392,7 +392,6 @@ class CompletableFutureUsageShowcaseTest : FunSpec({ 42 }.toCompletableFuture().await() shouldBe 42 - cf.thenApply { it }.handle { _, t -> t.shouldBeTypeOf() t.cause shouldBeSameInstanceAs rte diff --git a/cffu-core/src/test/java/io/foldright/test_utils/TestThreadPoolManager.kt b/cffu-core/src/test/java/io/foldright/test_utils/TestThreadPoolManager.kt index a610fd49..4b2383ad 100644 --- a/cffu-core/src/test/java/io/foldright/test_utils/TestThreadPoolManager.kt +++ b/cffu-core/src/test/java/io/foldright/test_utils/TestThreadPoolManager.kt @@ -86,12 +86,10 @@ fun shutdownExecutorService(vararg executors: ExecutorService) { } } - //////////////////////////////////////////////////////////////////////////////// // executors for kotest //////////////////////////////////////////////////////////////////////////////// - val testThreadPoolExecutor: ExecutorService = createThreadPool("CompletableFutureUseTest_ThreadPool") diff --git a/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt b/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt index 48fc340e..181b2e93 100644 --- a/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt +++ b/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt @@ -499,7 +499,6 @@ private fun Cffu.shouldNotMinCffu(recursive: Boolean = false) { if (recursive) newIncompleteFuture().shouldNotMinCffu() - //////////////////////////////////////////////////////////// // Cffu specified methods //////////////////////////////////////////////////////////// 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 83e34499..049b65c6 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 @@ -73,7 +73,6 @@ fun Collection>.allOfCompletableFuture(): CompletableFuture>.allOfCompletableFuture(): CompletableFuture = CompletableFuture.allOf(*(this as Array>).toCompletableFuture()) - /** * Returns a new CompletableFuture that is successful when all the given CompletableFutures success, * the results(`CompletableFuture`) of the given CompletableFutures are not reflected in the returned CompletableFuture, diff --git a/cffu-kotlin/src/test/java/io/foldright/cffu/test/CffuExtensionsTest.kt b/cffu-kotlin/src/test/java/io/foldright/cffu/test/CffuExtensionsTest.kt index abc74a26..5e32aed4 100644 --- a/cffu-kotlin/src/test/java/io/foldright/cffu/test/CffuExtensionsTest.kt +++ b/cffu-kotlin/src/test/java/io/foldright/cffu/test/CffuExtensionsTest.kt @@ -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 diff --git a/cffu-kotlin/src/test/java/io/foldright/cffu/test/CompletableFutureExtensionsTest.kt b/cffu-kotlin/src/test/java/io/foldright/cffu/test/CompletableFutureExtensionsTest.kt index 762b8709..4b97bef6 100644 --- a/cffu-kotlin/src/test/java/io/foldright/cffu/test/CompletableFutureExtensionsTest.kt +++ b/cffu-kotlin/src/test/java/io/foldright/cffu/test/CompletableFutureExtensionsTest.kt @@ -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*") { @@ -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 } ////////////////////////////////////////////////////////////////////////////////