Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Apr 22, 2024
1 parent 1164548 commit fcd25cf
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 125 deletions.
14 changes: 7 additions & 7 deletions cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public final <T> Cffu<List<T>> cffuAllOf(Cffu<? extends T>... cfs) {
@Contract(pure = true)
@SafeVarargs
public final <T> Cffu<List<T>> cffuAllOf(CompletableFuture<? extends T>... cfs) {
return new0(CompletableFutureUtils.allOfWithResult(cfs));
return new0(CompletableFutureUtils.allResultsOf(cfs));
}

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

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

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

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

/**
Expand Down Expand Up @@ -778,7 +778,7 @@ public final <T> Cffu<T> cffuAnyOfSuccess(Cffu<? extends T>... cfs) {
*/
@SafeVarargs
public final <T> Cffu<T> cffuAnyOfSuccess(CompletableFuture<? extends T>... cfs) {
return new0(CompletableFutureUtils.anyOfSuccessWithType(cfs));
return new0(CompletableFutureUtils.anyOfSuccess(cfs));
}

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

////////////////////////////////////////////////////////////////////////////////
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<? extends T>... cfs) {
public static <T> CompletableFuture<List<T>> allResultsOf(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<? extends T>... cfs) {
public static <T> CompletableFuture<List<T>> allResultsOfFastFail(CompletableFuture<? extends T>... cfs) {
requireCfsAndEleNonNull(cfs);
final int size = cfs.length;
if (size == 0) return CompletableFuture.completedFuture(arrayList());
Expand All @@ -134,7 +134,7 @@ public static <T> CompletableFuture<List<T>> allOfFastFailWithResult(Completable

// NOTE: fill the ONE MORE element of failedOrBeIncomplete HERE:
// a cf that is successful when all given cfs success, otherwise be incomplete
failedOrBeIncomplete[size] = allOfWithResult(successOrBeIncomplete);
failedOrBeIncomplete[size] = allResultsOf(successOrBeIncomplete);

return (CompletableFuture) CompletableFuture.anyOf(failedOrBeIncomplete);
}
Expand Down Expand Up @@ -192,13 +192,13 @@ private static void fill(CompletableFuture[] cfs,
* @return a new CompletableFuture that is completed with the result
* or exception from any of the given CompletableFutures when one completes
* @throws NullPointerException if the array or any of its elements are {@code null}
* @see #anyOfSuccessWithType(CompletableFuture[])
* @see #anyOfSuccess(CompletableFuture[])
* @see CompletableFuture#anyOf(CompletableFuture[])
*/
@Contract(pure = true)
@SafeVarargs
@SuppressWarnings("unchecked")
public static <T> CompletableFuture<T> anyOfWithType(CompletableFuture<? extends T>... cfs) {
public static <T> CompletableFuture<T> anyOf(CompletableFuture<? extends T>... cfs) {
return (CompletableFuture<T>) CompletableFuture.anyOf(cfs);
}

Expand All @@ -214,15 +214,16 @@ public static <T> CompletableFuture<T> anyOfWithType(CompletableFuture<? extends
* @return a new CompletableFuture that is successful
* when any of the given CompletableFutures success, with the same result
* @throws NullPointerException if the array or any of its elements are {@code null}
* @see #anyOfSuccessWithType(CompletableFuture[])
* @see #anyOf(CompletableFuture[])
*/
@Contract(pure = true)
@SafeVarargs
@SuppressWarnings({"unchecked", "rawtypes"})
public static CompletableFuture<Object> anyOfSuccess(CompletableFuture<?>... cfs) {
public static <T> CompletableFuture<T> anyOfSuccess(CompletableFuture<? extends T>... cfs) {
requireCfsAndEleNonNull(cfs);
final int size = cfs.length;
if (size == 0) return failedFuture(new NoCfsProvidedException());
if (size == 1) return (CompletableFuture<Object>) copy(cfs[0]);
if (size == 1) return (CompletableFuture) copy(cfs[0]);

// NOTE: fill ONE MORE element of successOrBeIncompleteCfs LATER
final CompletableFuture[] successOrBeIncomplete = new CompletableFuture[size + 1];
Expand All @@ -233,31 +234,7 @@ public static CompletableFuture<Object> anyOfSuccess(CompletableFuture<?>... cfs
// a cf that is failed when all given cfs fail, otherwise be incomplete
successOrBeIncomplete[size] = CompletableFuture.allOf(failedOrBeIncomplete);

return CompletableFuture.anyOf(successOrBeIncomplete);
}

/**
* Returns a new CompletableFuture that is successful when any of the given CompletableFutures success,
* with the same result. Otherwise, all the given CompletableFutures complete exceptionally,
* the returned CompletableFuture also does so, with a CompletionException holding
* an exception from any of the given CompletableFutures as its cause. If no CompletableFutures are provided,
* returns a new CompletableFuture that is already completed exceptionally
* with a CompletionException holding a {@link NoCfsProvidedException} as its cause.
* <p>
* Same as {@link #anyOfSuccess(CompletableFuture[])},
* but return result type is specified type instead of {@code Object}.
*
* @param cfs the CompletableFutures
* @return a new CompletableFuture that is successful
* when any of the given CompletableFutures success, with the same result
* @throws NullPointerException if the array or any of its elements are {@code null}
* @see #anyOfWithType(CompletableFuture[])
*/
@Contract(pure = true)
@SafeVarargs
@SuppressWarnings("unchecked")
public static <T> CompletableFuture<T> anyOfSuccessWithType(CompletableFuture<? extends T>... cfs) {
return (CompletableFuture<T>) anyOfSuccess(cfs);
return (CompletableFuture) CompletableFuture.anyOf(successOrBeIncomplete);
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -271,7 +248,7 @@ public static <T> CompletableFuture<T> anyOfSuccessWithType(CompletableFuture<?
*
* @return a new CompletableFuture that is completed when the given 2 CompletableFutures complete
* @throws NullPointerException if any of the given CompletableFutures are {@code null}
* @see #allOfWithResult(CompletableFuture[])
* @see #allResultsOf(CompletableFuture[])
* @see CompletableFuture#allOf(CompletableFuture[])
*/
@Contract(pure = true)
Expand All @@ -297,7 +274,7 @@ public static <T1, T2> CompletableFuture<Tuple2<T1, T2>> combine(
*
* @return a new CompletableFuture that is successful when the given two CompletableFutures success
* @throws NullPointerException if any of the given CompletableFutures are {@code null}
* @see #allOfFastFailWithResult(CompletableFuture[])
* @see #allResultsOfFastFail(CompletableFuture[])
* @see #allOfFastFail(CompletableFuture[])
*/
@Contract(pure = true)
Expand All @@ -322,7 +299,7 @@ public static <T1, T2> CompletableFuture<Tuple2<T1, T2>> combineFastFail(
*
* @return a new CompletableFuture that is completed when the given 3 CompletableFutures complete
* @throws NullPointerException if any of the given CompletableFutures are {@code null}
* @see #allOfWithResult(CompletableFuture[])
* @see #allResultsOf(CompletableFuture[])
* @see CompletableFuture#allOf(CompletableFuture[])
*/
@Contract(pure = true)
Expand All @@ -349,7 +326,7 @@ public static <T1, T2, T3> CompletableFuture<Tuple3<T1, T2, T3>> combine(
*
* @return a new CompletableFuture that is successful when the given three CompletableFutures success
* @throws NullPointerException if any of the given CompletableFutures are {@code null}
* @see #allOfFastFailWithResult(CompletableFuture[])
* @see #allResultsOfFastFail(CompletableFuture[])
* @see #allOfFastFail(CompletableFuture[])
*/
@Contract(pure = true)
Expand All @@ -375,7 +352,7 @@ public static <T1, T2, T3> CompletableFuture<Tuple3<T1, T2, T3>> combineFastFail
*
* @return a new CompletableFuture that is completed when the given 4 CompletableFutures complete
* @throws NullPointerException if any of the given CompletableFutures are {@code null}
* @see #allOfWithResult(CompletableFuture[])
* @see #allResultsOf(CompletableFuture[])
* @see CompletableFuture#allOf(CompletableFuture[])
*/
@Contract(pure = true)
Expand Down Expand Up @@ -404,7 +381,7 @@ public static <T1, T2, T3, T4> CompletableFuture<Tuple4<T1, T2, T3, T4>> combine
*
* @return a new CompletableFuture that is successful when the given 4 CompletableFutures success
* @throws NullPointerException if any of the given CompletableFutures are {@code null}
* @see #allOfFastFailWithResult(CompletableFuture[])
* @see #allResultsOfFastFail(CompletableFuture[])
* @see #allOfFastFail(CompletableFuture[])
*/
@Contract(pure = true)
Expand Down Expand Up @@ -432,7 +409,7 @@ public static <T1, T2, T3, T4> CompletableFuture<Tuple4<T1, T2, T3, T4>> combine
*
* @return a new CompletableFuture that is completed when the given 5 CompletableFutures complete
* @throws NullPointerException if any of the given CompletableFutures are {@code null}
* @see #allOfWithResult(CompletableFuture[])
* @see #allResultsOf(CompletableFuture[])
* @see CompletableFuture#allOf(CompletableFuture[])
*/
@Contract(pure = true)
Expand Down Expand Up @@ -462,7 +439,7 @@ public static <T1, T2, T3, T4, T5> CompletableFuture<Tuple5<T1, T2, T3, T4, T5>>
*
* @return a new CompletableFuture that is successful when the given 5 CompletableFutures success
* @throws NullPointerException if any of the given CompletableFutures are {@code null}
* @see #allOfFastFailWithResult(CompletableFuture[])
* @see #allResultsOfFastFail(CompletableFuture[])
* @see #allOfFastFail(CompletableFuture[])
*/
@Contract(pure = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see CffuFactory#cffuAnyOfSuccess(CompletableFuture[])
* @see CffuFactory#anyOfSuccess(Cffu[])
* @see CffuFactory#anyOfSuccess(CompletableFuture[])
* @see CompletableFutureUtils#anyOfSuccessWithType(CompletableFuture[])
* @see CompletableFutureUtils#anyOfSuccess(CompletableFuture[])
* @see CompletableFutureUtils#anyOfSuccess(CompletableFuture[])
*/
@SuppressWarnings("serial")
Expand Down
Loading

0 comments on commit fcd25cf

Please sign in to comment.