You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by zi...@apache.org on 2022/04/26 14:11:44 UTC
[pulsar] branch master updated: [improve][common] Use `Collection` to instead of `List` parameter type (#15329)
This is an automated email from the ASF dual-hosted git repository.
zike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 0c694cfdc9b [improve][common] Use `Collection` to instead of `List` parameter type (#15329)
0c694cfdc9b is described below
commit 0c694cfdc9b11f915f1da86260ad3655c2e99a35
Author: Qiang Zhao <74...@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.
---
.../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 a29ac8c2ee8..0e1bc2a3996 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 @@ import java.util.function.Supplier;
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]));
}
/**
- * 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, () -> {