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$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
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$0
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$0 → KILLED

35

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

36

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

38

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

51

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

56

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

Active mutators

Tests examined


Report generated by PIT 1.21.0