1 | package com.pivovarit.collectors; | |
2 | ||
3 | import java.util.List; | |
4 | import java.util.concurrent.CompletableFuture; | |
5 | import java.util.stream.Collector; | |
6 | import java.util.stream.Collectors; | |
7 | ||
8 | import static java.util.stream.Collectors.toList; | |
9 | ||
10 | /** | |
11 | * @author Grzegorz Piwowarek | |
12 | */ | |
13 | final class FutureCollectors { | |
14 | static <T, R> Collector<CompletableFuture<T>, ?, CompletableFuture<R>> toFuture(Collector<T, ?, R> collector) { | |
15 |
1
1. toFuture : replaced return value with null for com/pivovarit/collectors/FutureCollectors::toFuture → KILLED |
return Collectors.collectingAndThen(toList(), list -> { |
16 |
1
1. lambda$toFuture$0 : replaced return value with null for com/pivovarit/collectors/FutureCollectors::lambda$toFuture$0 → KILLED |
var future = CompletableFuture.allOf(list.toArray(CompletableFuture[]::new)) |
17 |
1
1. lambda$toFuture$1 : replaced return value with null for com/pivovarit/collectors/FutureCollectors::lambda$toFuture$1 → KILLED |
.thenApply(__ -> list.stream() |
18 | .map(CompletableFuture::join) | |
19 | .collect(collector)); | |
20 | ||
21 | for (var f : list) { | |
22 | f.whenComplete((__, throwable) -> { | |
23 |
1
1. lambda$toFuture$2 : negated conditional → KILLED |
if (throwable != null) { |
24 | future.completeExceptionally(throwable); | |
25 | } | |
26 | }); | |
27 | } | |
28 | ||
29 |
1
1. lambda$toFuture$3 : replaced return value with null for com/pivovarit/collectors/FutureCollectors::lambda$toFuture$3 → KILLED |
return future; |
30 | }); | |
31 | } | |
32 | ||
33 | static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<List<T>>> toFuture() { | |
34 |
1
1. toFuture : replaced return value with null for com/pivovarit/collectors/FutureCollectors::toFuture → KILLED |
return toFuture(toList()); |
35 | } | |
36 | } | |
Mutations | ||
15 |
1.1 |
|
16 |
1.1 |
|
17 |
1.1 |
|
23 |
1.1 |
|
29 |
1.1 |
|
34 |
1.1 |