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 0a761511..83ad58c8 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -266,11 +266,9 @@ public Cffu newIncompleteCffu() { @Contract(pure = true) public Cffu toCffu(CompletionStage stage) { requireNonNull(stage, "stage is null"); - - if (CompletableFutureUtils.isMinStageCf(stage)) { - return createMin((CompletableFuture) stage); - } else if (stage instanceof CompletableFuture) { - return create((CompletableFuture) stage); + if (stage instanceof CompletableFuture) { + final CompletableFuture cf = (CompletableFuture) stage; + return CompletableFutureUtils.isMinStageCf(cf) ? createMin(cf) : create(cf); } else if (stage instanceof Cffu) { return ((Cffu) stage).resetCffuFactory(this); } 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 08703cb2..6d1db59b 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -256,7 +256,6 @@ public static CompletableFuture> mostResultsOfSuccess( .handle((unused, ex) -> arrayList(MGetSuccessNow0(valueIfNotSuccess, cfArray))); } - /** * Multi-Gets(MGet) the results in the same order of the given cfs, * use the result value if the given stage is completed successfully, else use the given valueIfNotSuccess @@ -322,8 +321,8 @@ private static void fill(CompletionStage[] css, * IGNORE the compile-time type check. */ @SuppressWarnings({"unchecked", "rawtypes"}) - private static CompletableFuture f_cast(CompletableFuture f) { - return (CompletableFuture) f; + private static CompletableFuture f_cast(CompletableFuture cf) { + return (CompletableFuture) cf; } /** @@ -393,8 +392,8 @@ private static CompletableFuture toNonMinCfCopy(CompletionStage boolean isMinStageCf(CompletionStage s) { - return "java.util.concurrent.CompletableFuture$MinimalStage".equals(s.getClass().getName()); + static boolean isMinStageCf(CompletableFuture cf) { + return "java.util.concurrent.CompletableFuture$MinimalStage".equals(cf.getClass().getName()); } //////////////////////////////////////////////////////////////////////////////// @@ -1480,8 +1479,7 @@ C exceptionallyAsync(C cf, Function fn, Executor executo * @return a new CompletableFuture * @see #cffuOrTimeout(CompletableFuture, Executor, long, TimeUnit) */ - public static > C cffuOrTimeout( - C cf, long timeout, TimeUnit unit) { + public static > C cffuOrTimeout(C cf, long timeout, TimeUnit unit) { return cffuOrTimeout(cf, AsyncPoolHolder.ASYNC_POOL, timeout, unit); } @@ -1900,8 +1898,7 @@ public static CffuState state(Future cf) { * @param supplier a function returning the value to be used to complete given CompletableFuture * @return the given CompletableFuture */ - public static > - C completeAsync(C cf, Supplier supplier) { + public static > C completeAsync(C cf, Supplier supplier) { return completeAsync(cf, supplier, AsyncPoolHolder.ASYNC_POOL); }