From 1b4bbbe16270416b83850870efa95b5a6e27b400 Mon Sep 17 00:00:00 2001 From: mattison chao Date: Tue, 26 Apr 2022 14:00:15 +0800 Subject: [PATCH] [improve][common] Use `Collection` to instead of `List` parameter type. --- .../org/apache/pulsar/common/util/FutureUtil.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java b/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java index a29ac8c2ee8b4..0e1bc2a3996ea 100644 --- a/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java +++ b/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java @@ -19,7 +19,7 @@ package org.apache.pulsar.common.util; import java.time.Duration; -import java.util.List; +import java.util.Collection; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -36,35 +36,36 @@ public class FutureUtil { /** - * Return a future that represents the completion of the futures in the provided list. + * Return a future that represents the completion of the futures in the provided Collection. * * @param futures futures to wait for * @return a new CompletableFuture that is completed when all of the given CompletableFutures complete */ - public static CompletableFuture waitForAll(List> futures) { + public static CompletableFuture waitForAll(Collection> futures) { return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); } /** - * Return a future that represents the completion of any future in the provided list. + * Return a future that represents the completion of any future in the provided Collection. * * @param futures futures to wait any * @return a new CompletableFuture that is completed when any of the given CompletableFutures complete */ - public static CompletableFuture waitForAny(List> futures) { + public static CompletableFuture waitForAny(Collection> futures) { return CompletableFuture.anyOf(futures.toArray(new CompletableFuture[0])); } /** - * Return a future that represents the completion of the futures in the provided list. + * Return a future that represents the completion of the futures in the provided Collection. * The future will support {@link CompletableFuture#cancel(boolean)}. It will cancel * all unfinished futures when the future gets cancelled. * * @param futures futures to wait for * @return a new CompletableFuture that is completed when all of the given CompletableFutures complete */ - public static CompletableFuture waitForAllAndSupportCancel(List> futures) { + public static CompletableFuture waitForAllAndSupportCancel( + Collection> futures) { CompletableFuture[] futuresArray = futures.toArray(new CompletableFuture[0]); CompletableFuture combinedFuture = CompletableFuture.allOf(futuresArray); whenCancelledOrTimedOut(combinedFuture, () -> {