1 | package com.pivovarit.collectors; | |
2 | ||
3 | import java.util.List; | |
4 | import java.util.concurrent.CompletableFuture; | |
5 | import java.util.function.Function; | |
6 | import java.util.stream.Stream; | |
7 | import java.util.stream.StreamSupport; | |
8 | ||
9 | sealed interface CompletionStrategy<T> extends Function<List<CompletableFuture<T>>, Stream<T>> permits CompletionStrategy.Unordered, CompletionStrategy.Ordered { | |
10 | ||
11 | Unordered<?> UNORDERED = new Unordered<>(); | |
12 | Ordered<?> ORDERED = new Ordered<>(); | |
13 | ||
14 | static <R> CompletionStrategy<R> unordered() { | |
15 |
1
1. unordered : replaced return value with null for com/pivovarit/collectors/CompletionStrategy::unordered → KILLED |
return (CompletionStrategy<R>) UNORDERED; |
16 | } | |
17 | ||
18 | static <R> CompletionStrategy<R> ordered() { | |
19 |
1
1. ordered : replaced return value with null for com/pivovarit/collectors/CompletionStrategy::ordered → KILLED |
return (CompletionStrategy<R>) ORDERED; |
20 | } | |
21 | ||
22 | final class Unordered<T> implements CompletionStrategy<T> { | |
23 | @Override | |
24 | public Stream<T> apply(List<CompletableFuture<T>> futures) { | |
25 |
1
1. apply : replaced return value with Stream.empty for com/pivovarit/collectors/CompletionStrategy$Unordered::apply → KILLED |
return StreamSupport.stream(new CompletionOrderSpliterator<>(futures), false); |
26 | } | |
27 | } | |
28 | ||
29 | final class Ordered<T> implements CompletionStrategy<T> { | |
30 | @Override | |
31 | public Stream<T> apply(List<CompletableFuture<T>> futures) { | |
32 |
1
1. apply : replaced return value with Stream.empty for com/pivovarit/collectors/CompletionStrategy$Ordered::apply → KILLED |
return futures.stream().map(CompletableFuture::join); |
33 | } | |
34 | } | |
35 | } | |
Mutations | ||
15 |
1.1 |
|
19 |
1.1 |
|
25 |
1.1 |
|
32 |
1.1 |