Skip to content

Commit

Permalink
feat: add covariance to methods of CffuFactory/`CompletableFutureUt…
Browse files Browse the repository at this point in the history
…ils`/`CompletableFutureExtensions` 🧬
  • Loading branch information
oldratlee committed Apr 23, 2024
1 parent b4a7201 commit cfae72c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
28 changes: 16 additions & 12 deletions cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,9 @@ public Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) {
*/
@Contract(pure = true)
@SafeVarargs
public final <T> Cffu<List<T>> cffuAllOf(Cffu<T>... cfs) {
return cffuAllOf(toCompletableFutureArray(cfs));
@SuppressWarnings({"rawtypes", "unchecked"})
public final <T> Cffu<List<T>> cffuAllOf(Cffu<? extends T>... cfs) {
return cffuAllOf(toCompletableFutureArray((Cffu[]) cfs));
}

/**
Expand All @@ -622,7 +623,7 @@ public final <T> Cffu<List<T>> cffuAllOf(Cffu<T>... cfs) {
*/
@Contract(pure = true)
@SafeVarargs
public final <T> Cffu<List<T>> cffuAllOf(CompletableFuture<T>... cfs) {
public final <T> Cffu<List<T>> cffuAllOf(CompletableFuture<? extends T>... cfs) {
return new0(CompletableFutureUtils.allOfWithResult(cfs));
}

Expand Down Expand Up @@ -654,8 +655,9 @@ public <T> Cffu<List<T>> cffuAllOf() {
*/
@Contract(pure = true)
@SafeVarargs
public final <T> Cffu<List<T>> cffuAllOfFastFail(Cffu<T>... cfs) {
return cffuAllOfFastFail(toCompletableFutureArray(cfs));
@SuppressWarnings({"rawtypes", "unchecked"})
public final <T> Cffu<List<T>> cffuAllOfFastFail(Cffu<? extends T>... cfs) {
return cffuAllOfFastFail(toCompletableFutureArray((Cffu[]) cfs));
}

/**
Expand All @@ -676,7 +678,7 @@ public final <T> Cffu<List<T>> cffuAllOfFastFail(Cffu<T>... cfs) {
*/
@Contract(pure = true)
@SafeVarargs
public final <T> Cffu<List<T>> cffuAllOfFastFail(CompletableFuture<T>... cfs) {
public final <T> Cffu<List<T>> cffuAllOfFastFail(CompletableFuture<? extends T>... cfs) {
return new0(CompletableFutureUtils.allOfFastFailWithResult(cfs));
}

Expand Down Expand Up @@ -705,8 +707,9 @@ public <T> Cffu<List<T>> cffuAllOfFastFail() {
*/
@Contract(pure = true)
@SafeVarargs
public final <T> Cffu<T> cffuAnyOf(Cffu<T>... cfs) {
return cffuAnyOf(toCompletableFutureArray(cfs));
@SuppressWarnings({"unchecked", "rawtypes"})
public final <T> Cffu<T> cffuAnyOf(Cffu<? extends T>... cfs) {
return cffuAnyOf(toCompletableFutureArray((Cffu[]) cfs));
}

/**
Expand All @@ -722,7 +725,7 @@ public final <T> Cffu<T> cffuAnyOf(Cffu<T>... cfs) {
*/
@Contract(pure = true)
@SafeVarargs
public final <T> Cffu<T> cffuAnyOf(CompletableFuture<T>... cfs) {
public final <T> Cffu<T> cffuAnyOf(CompletableFuture<? extends T>... cfs) {
return new0(CompletableFutureUtils.anyOfWithType(cfs));
}

Expand Down Expand Up @@ -752,8 +755,9 @@ public <T> Cffu<T> cffuAnyOf() {
* @see #cffuAnyOf(Cffu[])
*/
@SafeVarargs
public final <T> Cffu<T> cffuAnyOfSuccess(Cffu<T>... cfs) {
return cffuAnyOfSuccess(toCompletableFutureArray(cfs));
@SuppressWarnings({"rawtypes", "unchecked"})
public final <T> Cffu<T> cffuAnyOfSuccess(Cffu<? extends T>... cfs) {
return cffuAnyOfSuccess(toCompletableFutureArray((Cffu[]) cfs));
}

/**
Expand All @@ -773,7 +777,7 @@ public final <T> Cffu<T> cffuAnyOfSuccess(Cffu<T>... cfs) {
* @see #cffuAnyOf(Cffu[])
*/
@SafeVarargs
public final <T> Cffu<T> cffuAnyOfSuccess(CompletableFuture<T>... cfs) {
public final <T> Cffu<T> cffuAnyOfSuccess(CompletableFuture<? extends T>... cfs) {
return new0(CompletableFutureUtils.anyOfSuccessWithType(cfs));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class CompletableFutureUtils {
@Contract(pure = true)
@SafeVarargs
@SuppressWarnings("unchecked")
public static <T> CompletableFuture<List<T>> allOfWithResult(CompletableFuture<T>... cfs) {
public static <T> CompletableFuture<List<T>> allOfWithResult(CompletableFuture<? extends T>... cfs) {
requireCfsAndEleNonNull(cfs);
final int size = cfs.length;
if (size == 0) return CompletableFuture.completedFuture(arrayList());
Expand Down Expand Up @@ -121,7 +121,7 @@ public static CompletableFuture<Void> allOfFastFail(CompletableFuture<?>... cfs)
@Contract(pure = true)
@SafeVarargs
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T> CompletableFuture<List<T>> allOfFastFailWithResult(CompletableFuture<T>... cfs) {
public static <T> CompletableFuture<List<T>> allOfFastFailWithResult(CompletableFuture<? extends T>... cfs) {
requireCfsAndEleNonNull(cfs);
final int size = cfs.length;
if (size == 0) return CompletableFuture.completedFuture(arrayList());
Expand Down Expand Up @@ -198,7 +198,7 @@ private static void fill(CompletableFuture[] cfs,
@Contract(pure = true)
@SafeVarargs
@SuppressWarnings("unchecked")
public static <T> CompletableFuture<T> anyOfWithType(CompletableFuture<T>... cfs) {
public static <T> CompletableFuture<T> anyOfWithType(CompletableFuture<? extends T>... cfs) {
return (CompletableFuture<T>) CompletableFuture.anyOf(cfs);
}

Expand Down Expand Up @@ -256,7 +256,7 @@ public static CompletableFuture<Object> anyOfSuccess(CompletableFuture<?>... cfs
@Contract(pure = true)
@SafeVarargs
@SuppressWarnings("unchecked")
public static <T> CompletableFuture<T> anyOfSuccessWithType(CompletableFuture<T>... cfs) {
public static <T> CompletableFuture<T> anyOfSuccessWithType(CompletableFuture<? extends T>... cfs) {
return (CompletableFuture<T>) anyOfSuccess(cfs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun <T> Collection<CompletableFuture<T>>.allOfCompletableFuture(): CompletableFu
* @see allOfCffu
* @see allOfCompletableFutureVoid
*/
fun <T> Array<CompletableFuture<T>>.allOfCompletableFuture(): CompletableFuture<List<T>> =
fun <T> Array<out CompletableFuture<T>>.allOfCompletableFuture(): CompletableFuture<List<T>> =
CompletableFutureUtils.allOfWithResult(*this)

/**
Expand Down Expand Up @@ -137,7 +137,7 @@ fun <T> Collection<CompletableFuture<T>>.allOfFastFailCompletableFuture(): Compl
* @see allOfFastFailCffu
* @see allOfFastFailCompletableFutureVoid
*/
fun <T> Array<CompletableFuture<T>>.allOfFastFailCompletableFuture(): CompletableFuture<List<T>> =
fun <T> Array<out CompletableFuture<T>>.allOfFastFailCompletableFuture(): CompletableFuture<List<T>> =
CompletableFutureUtils.allOfFastFailWithResult(*this)

/**
Expand Down Expand Up @@ -217,7 +217,7 @@ fun <T> Collection<CompletableFuture<T>>.anyOfCompletableFuture(): CompletableFu
* @see anyOfCffu
* @see anyOfCompletableFutureAny
*/
fun <T> Array<CompletableFuture<T>>.anyOfCompletableFuture(): CompletableFuture<T> =
fun <T> Array<out CompletableFuture<T>>.anyOfCompletableFuture(): CompletableFuture<T> =
CompletableFutureUtils.anyOfWithType(*this)

/**
Expand Down Expand Up @@ -285,7 +285,7 @@ fun <T> Collection<CompletableFuture<T>>.anyOfSuccessCompletableFuture(): Comple
* @see anyOfCompletableFuture
* @see CompletableFutureUtils.anyOfSuccessWithType
*/
fun <T> Array<CompletableFuture<T>>.anyOfSuccessCompletableFuture(): CompletableFuture<T> =
fun <T> Array<out CompletableFuture<T>>.anyOfSuccessCompletableFuture(): CompletableFuture<T> =
CompletableFutureUtils.anyOfSuccessWithType(*this)

/**
Expand Down

0 comments on commit cfae72c

Please sign in to comment.