This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 08219aef8840cb00369ea8d7aada42754d510f4d
Author: Qiang Zhao <74767115+mattisonc...@users.noreply.github.com>
AuthorDate: Tue Apr 26 22:11:35 2022 +0800

    [improve][common] Use `Collection` to instead of `List` parameter type 
(#15329)
    
    ### Motivation
    
    We can use `Collection` instead of `List` parameter type in `FutureUtil` 
for better compatibility.
    For example when we need to use the values of `Map`:
    
    ```java
    FutureUtil.waitForAll(map.values());
    ```
    ### Modifications
    
    - Use `Collection` instead of `List` parameter type.
    
    (cherry picked from commit 0c694cfdc9b11f915f1da86260ad3655c2e99a35)
---
 .../java/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 f51888a76df..e5c2caeb7d0 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;
@@ -38,22 +38,22 @@ import java.util.stream.Collectors;
 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<Void> waitForAll(List<? extends 
CompletableFuture<?>> futures) {
+    public static CompletableFuture<Void> waitForAll(Collection<? extends 
CompletableFuture<?>> 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<Object> waitForAny(List<? extends 
CompletableFuture<?>> futures) {
+    public static CompletableFuture<Object> waitForAny(Collection<? extends 
CompletableFuture<?>> futures) {
         return CompletableFuture.anyOf(futures.toArray(new 
CompletableFuture[0]));
     }
 
@@ -101,14 +101,15 @@ 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.
      * 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<Void> waitForAllAndSupportCancel(List<? 
extends CompletableFuture<?>> futures) {
+    public static CompletableFuture<Void> waitForAllAndSupportCancel(
+                                                    Collection<? extends 
CompletableFuture<?>> futures) {
         CompletableFuture[] futuresArray = futures.toArray(new 
CompletableFuture[0]);
         CompletableFuture<Void> combinedFuture = 
CompletableFuture.allOf(futuresArray);
         whenCancelledOrTimedOut(combinedFuture, () -> {

Reply via email to