From 0f68b51781b61a6b2c5b0671982d37a8c448503d Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 20 Apr 2024 20:10:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20covariant=20for=20methods=20of=20?= =?UTF-8?q?`CffuFactory`/`CompletableFutureUtils`/`CompletableFutureExtens?= =?UTF-8?q?ions`=20=F0=9F=A7=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/foldright/cffu/CffuFactory.java | 28 +++++++++++-------- .../cffu/CompletableFutureUtils.java | 8 +++--- .../kotlin/CompletableFutureExtensions.kt | 8 +++--- 3 files changed, 24 insertions(+), 20 deletions(-) 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 51f71ec5..aeaf3445 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -602,8 +602,9 @@ public Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) { */ @Contract(pure = true) @SafeVarargs - public final Cffu> cffuAllOf(Cffu... cfs) { - return cffuAllOf(toCompletableFutureArray(cfs)); + @SuppressWarnings({"rawtypes", "unchecked"}) + public final Cffu> cffuAllOf(Cffu... cfs) { + return cffuAllOf(toCompletableFutureArray((Cffu[]) cfs)); } /** @@ -622,7 +623,7 @@ public final Cffu> cffuAllOf(Cffu... cfs) { */ @Contract(pure = true) @SafeVarargs - public final Cffu> cffuAllOf(CompletableFuture... cfs) { + public final Cffu> cffuAllOf(CompletableFuture... cfs) { return new0(CompletableFutureUtils.allOfWithResult(cfs)); } @@ -654,8 +655,9 @@ public Cffu> cffuAllOf() { */ @Contract(pure = true) @SafeVarargs - public final Cffu> cffuAllOfFastFail(Cffu... cfs) { - return cffuAllOfFastFail(toCompletableFutureArray(cfs)); + @SuppressWarnings({"rawtypes", "unchecked"}) + public final Cffu> cffuAllOfFastFail(Cffu... cfs) { + return cffuAllOfFastFail(toCompletableFutureArray((Cffu[]) cfs)); } /** @@ -676,7 +678,7 @@ public final Cffu> cffuAllOfFastFail(Cffu... cfs) { */ @Contract(pure = true) @SafeVarargs - public final Cffu> cffuAllOfFastFail(CompletableFuture... cfs) { + public final Cffu> cffuAllOfFastFail(CompletableFuture... cfs) { return new0(CompletableFutureUtils.allOfFastFailWithResult(cfs)); } @@ -705,8 +707,9 @@ public Cffu> cffuAllOfFastFail() { */ @Contract(pure = true) @SafeVarargs - public final Cffu cffuAnyOf(Cffu... cfs) { - return cffuAnyOf(toCompletableFutureArray(cfs)); + @SuppressWarnings({"unchecked", "rawtypes"}) + public final Cffu cffuAnyOf(Cffu... cfs) { + return cffuAnyOf(toCompletableFutureArray((Cffu[]) cfs)); } /** @@ -722,7 +725,7 @@ public final Cffu cffuAnyOf(Cffu... cfs) { */ @Contract(pure = true) @SafeVarargs - public final Cffu cffuAnyOf(CompletableFuture... cfs) { + public final Cffu cffuAnyOf(CompletableFuture... cfs) { return new0(CompletableFutureUtils.anyOfWithType(cfs)); } @@ -752,8 +755,9 @@ public Cffu cffuAnyOf() { * @see #cffuAnyOf(Cffu[]) */ @SafeVarargs - public final Cffu cffuAnyOfSuccess(Cffu... cfs) { - return cffuAnyOfSuccess(toCompletableFutureArray(cfs)); + @SuppressWarnings({"rawtypes", "unchecked"}) + public final Cffu cffuAnyOfSuccess(Cffu... cfs) { + return cffuAnyOfSuccess(toCompletableFutureArray((Cffu[]) cfs)); } /** @@ -773,7 +777,7 @@ public final Cffu cffuAnyOfSuccess(Cffu... cfs) { * @see #cffuAnyOf(Cffu[]) */ @SafeVarargs - public final Cffu cffuAnyOfSuccess(CompletableFuture... cfs) { + public final Cffu cffuAnyOfSuccess(CompletableFuture... cfs) { return new0(CompletableFutureUtils.anyOfSuccessWithType(cfs)); } 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 923a95a1..d1bede14 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -50,7 +50,7 @@ public final class CompletableFutureUtils { @Contract(pure = true) @SafeVarargs @SuppressWarnings("unchecked") - public static CompletableFuture> allOfWithResult(CompletableFuture... cfs) { + public static CompletableFuture> allOfWithResult(CompletableFuture... cfs) { requireCfsAndEleNonNull(cfs); final int size = cfs.length; if (size == 0) return CompletableFuture.completedFuture(arrayList()); @@ -121,7 +121,7 @@ public static CompletableFuture allOfFastFail(CompletableFuture... cfs) @Contract(pure = true) @SafeVarargs @SuppressWarnings({"unchecked", "rawtypes"}) - public static CompletableFuture> allOfFastFailWithResult(CompletableFuture... cfs) { + public static CompletableFuture> allOfFastFailWithResult(CompletableFuture... cfs) { requireCfsAndEleNonNull(cfs); final int size = cfs.length; if (size == 0) return CompletableFuture.completedFuture(arrayList()); @@ -198,7 +198,7 @@ private static void fill(CompletableFuture[] cfs, @Contract(pure = true) @SafeVarargs @SuppressWarnings("unchecked") - public static CompletableFuture anyOfWithType(CompletableFuture... cfs) { + public static CompletableFuture anyOfWithType(CompletableFuture... cfs) { return (CompletableFuture) CompletableFuture.anyOf(cfs); } @@ -256,7 +256,7 @@ public static CompletableFuture anyOfSuccess(CompletableFuture... cfs @Contract(pure = true) @SafeVarargs @SuppressWarnings("unchecked") - public static CompletableFuture anyOfSuccessWithType(CompletableFuture... cfs) { + public static CompletableFuture anyOfSuccessWithType(CompletableFuture... cfs) { return (CompletableFuture) anyOfSuccess(cfs); } 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 0c606add..05cfb044 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 @@ -57,7 +57,7 @@ fun Collection>.allOfCompletableFuture(): CompletableFu * @see allOfCffu * @see allOfCompletableFutureVoid */ -fun Array>.allOfCompletableFuture(): CompletableFuture> = +fun Array>.allOfCompletableFuture(): CompletableFuture> = CompletableFutureUtils.allOfWithResult(*this) /** @@ -137,7 +137,7 @@ fun Collection>.allOfFastFailCompletableFuture(): Compl * @see allOfFastFailCffu * @see allOfFastFailCompletableFutureVoid */ -fun Array>.allOfFastFailCompletableFuture(): CompletableFuture> = +fun Array>.allOfFastFailCompletableFuture(): CompletableFuture> = CompletableFutureUtils.allOfFastFailWithResult(*this) /** @@ -217,7 +217,7 @@ fun Collection>.anyOfCompletableFuture(): CompletableFu * @see anyOfCffu * @see anyOfCompletableFutureAny */ -fun Array>.anyOfCompletableFuture(): CompletableFuture = +fun Array>.anyOfCompletableFuture(): CompletableFuture = CompletableFutureUtils.anyOfWithType(*this) /** @@ -285,7 +285,7 @@ fun Collection>.anyOfSuccessCompletableFuture(): Comple * @see anyOfCompletableFuture * @see CompletableFutureUtils.anyOfSuccessWithType */ -fun Array>.anyOfSuccessCompletableFuture(): CompletableFuture = +fun Array>.anyOfSuccessCompletableFuture(): CompletableFuture = CompletableFutureUtils.anyOfSuccessWithType(*this) /**