2 * Copyright (c) 2010-2023 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;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
25 * Collector to combine a stream of CompletableFutures.
27 * @author Jochen Klein - Initial contribution
31 public class FutureCollector {
33 public static <X> Collector<CompletableFuture<X>, Set<CompletableFuture<X>>, CompletableFuture<@Nullable Void>> allOf() {
34 return Collector.<CompletableFuture<X>, Set<CompletableFuture<X>>, CompletableFuture<@Nullable Void>> of(
35 (Supplier<Set<CompletableFuture<X>>>) HashSet::new, Set::add, (left, right) -> {
38 }, a -> CompletableFuture.allOf(a.toArray(new CompletableFuture[a.size()])),
39 Collector.Characteristics.UNORDERED);