From 5ea450f1d47a239d71aacaa6cede55b4cc52d439 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 27 Jul 2024 18:21:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20remove=20convenient=20util=20method?= =?UTF-8?q?s=20for=20dangerous=20`cffuUnwrap`=20method=20=F0=9F=A7=B9=20?= =?UTF-8?q?=E2=9A=A0=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/foldright/cffu/Cffu.java | 4 --- .../java/io/foldright/cffu/CffuFactory.java | 21 +--------------- .../io/foldright/cffu/CffuFactoryTest.java | 16 ------------ .../foldright/cffu/kotlin/CffuExtensions.kt | 25 ------------------- .../foldright/cffu/test/CffuExtensionsTest.kt | 19 -------------- 5 files changed, 1 insertion(+), 84 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 95f69f04..b244cd48 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java +++ b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java @@ -2903,13 +2903,9 @@ public void obtrudeException(Throwable ex) { /** * Returns the underlying CompletableFuture. * In general, you should NEVER use this method, use {@link #toCompletableFuture()} instead. - *

- * {@link CffuFactory#cffuArrayUnwrap(Cffu[])} is the batch operation to this method. * * @return the underlying CompletableFuture * @see #toCompletableFuture() - * @see CffuFactory#cffuArrayUnwrap(Cffu[]) - * @see #toCompletableFuture() */ @Contract(pure = true) @SuppressFBWarnings("EI_EXPOSE_REP") 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 c983ff45..c19a81f5 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -1611,30 +1611,11 @@ public Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) { // endregion //////////////////////////////////////////////////////////////////////////////// - // region# Conversion Methods(static methods) + // region# Conversion Methods // - // - cffuArrayUnwrap: Cffu[] -> CompletableFuture[] // - cffuListToArray: List -> Cffu[] //////////////////////////////////////////////////////////////////////////////// - /** - * A convenient util method for unwrap input {@link Cffu} array elements by {@link Cffu#cffuUnwrap()}. - * - * @param cfs the Cffus - * @see CompletableFutureUtils#toCompletableFutureArray(CompletionStage[]) - * @see Cffu#cffuUnwrap() - */ - @Contract(pure = true) - @SafeVarargs - public static CompletableFuture[] cffuArrayUnwrap(Cffu... cfs) { - @SuppressWarnings("unchecked") - CompletableFuture[] ret = new CompletableFuture[cfs.length]; - for (int i = 0; i < cfs.length; i++) { - ret[i] = requireNonNull(cfs[i], "cf" + (i + 1) + " is null").cffuUnwrap(); - } - return ret; - } - /** * Convert Cffu list to Cffu array. * 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 51118a06..4df97fd0 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java @@ -860,25 +860,9 @@ void test_toCffuArray() throws Exception { //////////////////////////////////////////////////////////////////////////////// // region# Conversion Methods(static methods) // - // - cffuArrayUnwrap: Cffu[] -> CompletableFuture[] // - cffuListToArray: List -> Cffu[] //////////////////////////////////////////////////////////////////////////////// - @Test - void test_cffuArrayUnwrap() { - @SuppressWarnings("unchecked") - CompletableFuture[] cfArray = new CompletableFuture[]{ - completedFuture(n), - completedFuture(anotherN) - }; - @SuppressWarnings("unchecked") - Cffu[] input = new Cffu[]{ - cffuFactory.toCffu(cfArray[0]), - cffuFactory.toCffu(cfArray[1]), - }; - assertArrayEquals(cfArray, CffuFactory.cffuArrayUnwrap(input)); - } - @Test void test_toCompletableFutureArray() { @SuppressWarnings("unchecked") 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 4c74a054..466f54d0 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 @@ -600,28 +600,3 @@ fun Collection>.anyOfCffu(cffuFactory: CffuFactory): */ fun Array>.anyOfCffu(cffuFactory: CffuFactory): Cffu = cffuFactory.anyOf(*this) - -// endregion -//////////////////////////////////////////////////////////////////////////////// -// region# cffuUnwrap methods for Collection/Array -//////////////////////////////////////////////////////////////////////////////// - -/** - * Unwrap input [Cffu] collection elements by [Cffu.cffuUnwrap]. - * - * This method is the same as [CffuFactory.cffuArrayUnwrap], providing this method is convenient for method chaining. - * - * @see CffuFactory.cffuArrayUnwrap - */ -fun Collection>.cffuUnwrap(): List> = - map { it.cffuUnwrap() } - -/** - * Unwrap input [Cffu] array elements by [Cffu.cffuUnwrap]. - * - * This method is the same as [CffuFactory.cffuArrayUnwrap], providing this method is convenient for method chaining. - * - * @see CffuFactory.cffuArrayUnwrap - */ -fun Array>.cffuUnwrap(): Array> = - CffuFactory.cffuArrayUnwrap(*this) 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 b682ea36..9543e9f6 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 @@ -655,23 +655,4 @@ class CffuExtensionsTest : FunSpec({ it.shouldNotBeTypeOf>>() } } - - //////////////////////////////////////// - // cffuUnwrap - //////////////////////////////////////// - - test("cffuUnwrap for Cffu collection/array") { - val range = 0 until 10 - val cfs: List> = range.map { - CompletableFuture.completedFuture(it) - } - val cfArray = cfs.toTypedArray() - - val cffus: List> = cfs.toCffu(testCffuFactory) - cffus.cffuUnwrap() shouldBe cfs - cffus.toSet().cffuUnwrap() shouldBe cfs - - val cffuArray: Array> = cffus.toTypedArray() - cffuArray.cffuUnwrap() shouldBe cfArray - } })