| 1 | package com.pivovarit.collectors; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | import java.util.Spliterator; | |
| 5 | import java.util.concurrent.BlockingQueue; | |
| 6 | import java.util.concurrent.CompletableFuture; | |
| 7 | import java.util.concurrent.LinkedBlockingQueue; | |
| 8 | import java.util.function.Consumer; | |
| 9 | ||
| 10 | /** | |
| 11 | * @author Grzegorz Piwowarek | |
| 12 | */ | |
| 13 | final class CompletionOrderSpliterator<T> implements Spliterator<T> { | |
| 14 | ||
| 15 | private final int initialSize; | |
| 16 | private final BlockingQueue<CompletableFuture<T>> completed = new LinkedBlockingQueue<>(); | |
| 17 | private int remaining; | |
| 18 | ||
| 19 | CompletionOrderSpliterator(List<CompletableFuture<T>> futures) { | |
| 20 | this.initialSize = futures.size(); | |
| 21 | this.remaining = initialSize; | |
| 22 |
1
1. <init> : removed call to java/util/List::forEach → TIMED_OUT |
futures.forEach(f -> f.whenComplete((__, ___) -> completed.add(f))); |
| 23 | } | |
| 24 | ||
| 25 | @Override | |
| 26 | public boolean tryAdvance(Consumer<? super T> action) { | |
| 27 |
3
1. tryAdvance : negated conditional → TIMED_OUT 2. tryAdvance : changed conditional boundary → TIMED_OUT 3. tryAdvance : replaced boolean return with true for com/pivovarit/collectors/CompletionOrderSpliterator::tryAdvance → KILLED |
return remaining > 0 |
| 28 |
1
1. lambda$tryAdvance$0 : replaced Boolean return with False for com/pivovarit/collectors/CompletionOrderSpliterator::lambda$tryAdvance$0 → KILLED |
? nextCompleted().thenAccept(action).thenApply(__ -> true).join() |
| 29 | : false; | |
| 30 | } | |
| 31 | ||
| 32 | private CompletableFuture<T> nextCompleted() { | |
| 33 | try { | |
| 34 | var next = completed.take(); | |
| 35 |
1
1. nextCompleted : Replaced integer subtraction with addition → TIMED_OUT |
remaining--; |
| 36 |
1
1. nextCompleted : replaced return value with null for com/pivovarit/collectors/CompletionOrderSpliterator::nextCompleted → KILLED |
return next; |
| 37 | } catch (InterruptedException e) { | |
| 38 |
1
1. nextCompleted : removed call to java/lang/Thread::interrupt → TIMED_OUT |
Thread.currentThread().interrupt(); |
| 39 | ||
| 40 | throw new RuntimeException(e); | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | @Override | |
| 45 | public Spliterator<T> trySplit() { | |
| 46 | return null; | |
| 47 | } | |
| 48 | ||
| 49 | @Override | |
| 50 | public long estimateSize() { | |
| 51 |
1
1. estimateSize : replaced long return with 0 for com/pivovarit/collectors/CompletionOrderSpliterator::estimateSize → KILLED |
return initialSize; |
| 52 | } | |
| 53 | ||
| 54 | @Override | |
| 55 | public int characteristics() { | |
| 56 |
1
1. characteristics : replaced int return with 0 for com/pivovarit/collectors/CompletionOrderSpliterator::characteristics → SURVIVED |
return SIZED | IMMUTABLE | NONNULL; |
| 57 | } | |
| 58 | } | |
Mutations | ||
| 22 |
1.1 |
|
| 27 |
1.1 2.2 3.3 |
|
| 28 |
1.1 |
|
| 35 |
1.1 |
|
| 36 |
1.1 |
|
| 38 |
1.1 |
|
| 51 |
1.1 |
|
| 56 |
1.1 |