2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mqtt.generic.utils;
15 import java.util.HashSet;
17 import java.util.concurrent.CompletableFuture;
18 import java.util.function.Supplier;
19 import java.util.stream.Collector;
22 * Collector to combine a stream of CompletableFutures.
24 * @author Jochen Klein - Initial contribution
27 public class FutureCollector {
29 public static <X> Collector<CompletableFuture<X>, Set<CompletableFuture<X>>, CompletableFuture<Void>> allOf() {
30 return Collector.<CompletableFuture<X>, Set<CompletableFuture<X>>, CompletableFuture<Void>> of(
31 (Supplier<Set<CompletableFuture<X>>>) HashSet::new, Set::add, (left, right) -> {
35 return CompletableFuture.allOf(a.toArray(new CompletableFuture[a.size()]));
36 }, Collector.Characteristics.UNORDERED);