Skip to content

Commit

Permalink
refactor: change CffuFactory.thenTupleM* methods to the memeber met…
Browse files Browse the repository at this point in the history
…hods of `Cffu` 👯
  • Loading branch information
oldratlee committed Jun 22, 2024
1 parent d706e38 commit cb9f1f4
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 181 deletions.
155 changes: 155 additions & 0 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.foldright.cffu.tuple.Tuple2;
import io.foldright.cffu.tuple.Tuple3;
import io.foldright.cffu.tuple.Tuple4;
import io.foldright.cffu.tuple.Tuple5;
import org.jetbrains.annotations.Blocking;
import org.jetbrains.annotations.Contract;

Expand Down Expand Up @@ -201,6 +205,157 @@ public Cffu<Void> thenRunAsync(Runnable action, Executor executor) {
return reset0(cf.thenRunAsync(action, executor));
}

////////////////////////////////////////////////////////////
// region## Then-Multi-Actions(thenM*) Methods
////////////////////////////////////////////////////////////

// TODO: TO BE implemented!!

// endregion
////////////////////////////////////////////////////////////
// region## Then-Tuple-Multi-Actions(thenTupleM*) Methods
////////////////////////////////////////////////////////////

/**
* Returns a new Cffu that, when this Cffu completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(CompletionStage, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyFastFailAsync(
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2) {
return reset0(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, fn1, fn2));
}

/**
* Returns a new Cffu that, when this Cffu completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(CompletionStage, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyFastFailAsync(
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3) {
return reset0(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, fn1, fn2, fn3));
}

/**
* Returns a new Cffu that, when this Cffu completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(CompletionStage, Function, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyFastFailAsync(
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3, Function<? super T, ? extends U4> fn4) {
return reset0(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, fn1, fn2, fn3, fn4));
}

/**
* Returns a new Cffu that, when this Cffu completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(CompletionStage, Function, Function, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyFastFailAsync(
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3, Function<? super T, ? extends U4> fn4,
Function<? super T, ? extends U5> fn5) {
return reset0(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, fn1, fn2, fn3, fn4, fn5));
}

/**
* Returns a new Cffu that, when this Cffu completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyAsync(
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2) {
return reset0(CompletableFutureUtils.thenTupleMApplyAsync(cf, fn1, fn2));
}

/**
* Returns a new Cffu that, when this Cffu completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyAsync(
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3) {
return reset0(CompletableFutureUtils.thenTupleMApplyAsync(cf, fn1, fn2, fn3));
}

/**
* Returns a new Cffu that, when this Cffu completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyAsync(
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3, Function<? super T, ? extends U4> fn4) {
return reset0(CompletableFutureUtils.thenTupleMApplyAsync(cf, fn1, fn2, fn3, fn4));
}

/**
* Returns a new Cffu that, when this Cffu completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with this Cffu's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyAsync(
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3, Function<? super T, ? extends U4> fn4,
Function<? super T, ? extends U5> fn5) {
return reset0(CompletableFutureUtils.thenTupleMApplyAsync(cf, fn1, fn2, fn3, fn4, fn5));
}

// endregion
////////////////////////////////////////////////////////////////////////////////
// region# thenBoth* Methods(binary input) of CompletionStage
Expand Down
143 changes: 0 additions & 143 deletions cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,149 +676,6 @@ public <T1, T2, T3, T4, T5> Cffu<Tuple5<T1, T2, T3, T4, T5>> mostTupleOfSuccess(
return create(CompletableFutureUtils.mostTupleOfSuccess(defaultExecutor, timeout, unit, cf1, cf2, cf3, cf4, cf5));
}

/**
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(CompletionStage, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <T, U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyFastFailAsync(
CompletionStage<? extends T> cf, Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2) {
return create(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, fn1, fn2));
}

/**
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(CompletionStage, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <T, U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyFastFailAsync(
CompletionStage<? extends T> cf, Function<? super T, ? extends U1> fn1,
Function<? super T, ? extends U2> fn2, Function<? super T, ? extends U3> fn3) {
return create(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, fn1, fn2, fn3));
}

/**
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(CompletionStage, Function, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <T, U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyFastFailAsync(
CompletionStage<? extends T> cf,
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3, Function<? super T, ? extends U4> fn4) {
return create(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, fn1, fn2, fn3, fn4));
}

/**
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
* <p>
* This method is the same as {@link #thenTupleMApplyAsync(CompletionStage, Function, Function, Function, Function, Function)}
* except for the fast-fail behavior.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <T, U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyFastFailAsync(
CompletionStage<? extends T> cf, Function<? super T, ? extends U1> fn1,
Function<? super T, ? extends U2> fn2, Function<? super T, ? extends U3> fn3,
Function<? super T, ? extends U4> fn4, Function<? super T, ? extends U5> fn5) {
return create(CompletableFutureUtils.thenTupleMApplyFastFailAsync(cf, fn1, fn2, fn3, fn4, fn5));
}

/**
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <T, U1, U2> Cffu<Tuple2<U1, U2>> thenTupleMApplyAsync(
CompletionStage<? extends T> cf,
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2) {
return create(CompletableFutureUtils.thenTupleMApplyAsync(cf, fn1, fn2));
}

/**
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <T, U1, U2, U3> Cffu<Tuple3<U1, U2, U3>> thenTupleMApplyAsync(
CompletionStage<? extends T> cf, Function<? super T, ? extends U1> fn1,
Function<? super T, ? extends U2> fn2, Function<? super T, ? extends U3> fn3) {
return create(CompletableFutureUtils.thenTupleMApplyAsync(cf, fn1, fn2, fn3));
}

/**
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <T, U1, U2, U3, U4> Cffu<Tuple4<U1, U2, U3, U4>> thenTupleMApplyAsync(
CompletionStage<? extends T> cf,
Function<? super T, ? extends U1> fn1, Function<? super T, ? extends U2> fn2,
Function<? super T, ? extends U3> fn3, Function<? super T, ? extends U4> fn4) {
return create(CompletableFutureUtils.thenTupleMApplyAsync(cf, fn1, fn2, fn3, fn4));
}

/**
* Returns a new Cffu that, when the given stage completes normally,
* is executed using the {@link #defaultExecutor()},
* with the values obtained by calling the given Functions
* (with the given stage's result as the argument to the given functions)
* in the <strong>same order</strong> of the given Functions arguments.
*
* @return the new Cffu
*/
@Contract(pure = true)
public <T, U1, U2, U3, U4, U5> Cffu<Tuple5<U1, U2, U3, U4, U5>> thenTupleMApplyAsync(
CompletionStage<? extends T> cf, Function<? super T, ? extends U1> fn1,
Function<? super T, ? extends U2> fn2, Function<? super T, ? extends U3> fn3,
Function<? super T, ? extends U4> fn4, Function<? super T, ? extends U5> fn5) {
return create(CompletableFutureUtils.thenTupleMApplyAsync(cf, fn1, fn2, fn3, fn4, fn5));
}

// endregion
////////////////////////////////////////////////////////////////////////////////
// region## Immediate Value Argument Factory Methods
Expand Down
38 changes: 0 additions & 38 deletions cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,44 +662,6 @@ void test_tupleMSupplyAsync() throws Exception {
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.tupleMSupplyFastFailAsync(supplier_n, supplier_s, supplier_d, supplier_an, supplier_nn).get());
}

@Test
void test_thenTupleMApplyAsync() throws Exception {
final CompletableFuture<Integer> completed = completedFuture(n);
final Function<Integer,Integer> function_n = (x) -> {
sleep(100);
return n;
};

final Function<Integer,String> function_s = (x) -> {
sleep(100);
return s;
};

final Function<Integer,Double> function_d = (x) -> {
sleep(100);
return d;
};
final Function<Integer,Integer> function_an = (x) -> {
sleep(100);
return anotherN;
};
final Function<Integer,Integer> function_nn = (x) -> {
sleep(100);
return n+n;
};
assertEquals(Tuple2.of(n, s), cffuFactory.thenTupleMApplyAsync(completed,function_n, function_s).get());
assertEquals(Tuple2.of(n, s), cffuFactory.thenTupleMApplyFastFailAsync(completed,function_n, function_s).get());

assertEquals(Tuple3.of(n, s, d), cffuFactory.thenTupleMApplyAsync(completed,function_n, function_s, function_d).get());
assertEquals(Tuple3.of(n, s, d), cffuFactory.thenTupleMApplyFastFailAsync(completed,function_n, function_s, function_d).get());

assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.thenTupleMApplyAsync(completed,function_n, function_s, function_d, function_an).get());
assertEquals(Tuple4.of(n, s, d, anotherN), cffuFactory.thenTupleMApplyFastFailAsync(completed,function_n, function_s, function_d, function_an).get());

assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.thenTupleMApplyAsync(completed,function_n, function_s, function_d, function_an, function_nn).get());
assertEquals(Tuple5.of(n, s, d, anotherN, n + n), cffuFactory.thenTupleMApplyFastFailAsync(completed,function_n, function_s, function_d, function_an, function_nn).get());
}

////////////////////////////////////////////////////////////////////////////////
//# Conversion (Static) Methods
//
Expand Down
Loading

0 comments on commit cb9f1f4

Please sign in to comment.