CompletionOrderSpliterator.java

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$2 : replaced Boolean return with False for com/pivovarit/collectors/CompletionOrderSpliterator::lambda$tryAdvance$2 → KILLED
          ? nextCompleted().thenAccept(action).thenApply(__ -> true).join()
29
          : false;
30
    }
31
32
    private CompletableFuture<T> nextCompleted() {
33 1 1. nextCompleted : Replaced integer subtraction with addition → TIMED_OUT
        remaining--;
34
        try {
35 1 1. nextCompleted : replaced return value with null for com/pivovarit/collectors/CompletionOrderSpliterator::nextCompleted → KILLED
            return completed.take();
36
        } catch (InterruptedException e) {
37 1 1. nextCompleted : removed call to java/lang/Thread::interrupt → TIMED_OUT
            Thread.currentThread().interrupt();
38
39
            throw new RuntimeException(e);
40
        }
41
    }
42
43
    @Override
44
    public Spliterator<T> trySplit() {
45
        return null;
46
    }
47
48
    @Override
49
    public long estimateSize() {
50 1 1. estimateSize : replaced long return with 0 for com/pivovarit/collectors/CompletionOrderSpliterator::estimateSize → KILLED
        return initialSize;
51
    }
52
53
    @Override
54
    public int characteristics() {
55 1 1. characteristics : replaced int return with 0 for com/pivovarit/collectors/CompletionOrderSpliterator::characteristics → SURVIVED
        return SIZED | IMMUTABLE | NONNULL;
56
    }
57
}
58
59

Mutations

22

1.1
Location : <init>
Killed by : none
removed call to java/util/List::forEach → TIMED_OUT

27

1.1
Location : tryAdvance
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : tryAdvance
Killed by : com.pivovarit.collectors.CompletionOrderSpliteratorTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.CompletionOrderSpliteratorTest]/[method:shouldNotConsumeOnEmpty()]
replaced boolean return with true for com/pivovarit/collectors/CompletionOrderSpliterator::tryAdvance → KILLED

3.3
Location : tryAdvance
Killed by : none
changed conditional boundary → TIMED_OUT

28

1.1
Location : lambda$tryAdvance$2
Killed by : com.pivovarit.collectors.CompletionOrderSpliteratorTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.CompletionOrderSpliteratorTest]/[method:shouldPropagateException()]
replaced Boolean return with False for com/pivovarit/collectors/CompletionOrderSpliterator::lambda$tryAdvance$2 → KILLED

33

1.1
Location : nextCompleted
Killed by : none
Replaced integer subtraction with addition → TIMED_OUT

35

1.1
Location : nextCompleted
Killed by : com.pivovarit.collectors.CompletionOrderSpliteratorTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.CompletionOrderSpliteratorTest]/[method:shouldStreamInCompletionOrder()]
replaced return value with null for com/pivovarit/collectors/CompletionOrderSpliterator::nextCompleted → KILLED

37

1.1
Location : nextCompleted
Killed by : none
removed call to java/lang/Thread::interrupt → TIMED_OUT

50

1.1
Location : estimateSize
Killed by : com.pivovarit.collectors.CompletionOrderSpliteratorTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.CompletionOrderSpliteratorTest]/[method:shouldPropagateException()]
replaced long return with 0 for com/pivovarit/collectors/CompletionOrderSpliterator::estimateSize → KILLED

55

1.1
Location : characteristics
Killed by : none
replaced int return with 0 for com/pivovarit/collectors/CompletionOrderSpliterator::characteristics → SURVIVED

Active mutators

Tests examined


Report generated by PIT 1.16.0