CompletionOrderSpliterator.java

1
/*
2
 * Copyright 2014-2026 Grzegorz Piwowarek, https://4comprehension.com/
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.pivovarit.collectors;
17
18
import java.util.List;
19
import java.util.Spliterator;
20
import java.util.concurrent.BlockingQueue;
21
import java.util.concurrent.CompletableFuture;
22
import java.util.concurrent.LinkedBlockingQueue;
23
import java.util.function.Consumer;
24
25
/**
26
 * @author Grzegorz Piwowarek
27
 */
28
final class CompletionOrderSpliterator<T> implements Spliterator<T> {
29
30
    private final int initialSize;
31
    private final BlockingQueue<CompletableFuture<T>> completed = new LinkedBlockingQueue<>();
32
    private int remaining;
33
34
    CompletionOrderSpliterator(List<CompletableFuture<T>> futures) {
35
        this.initialSize = futures.size();
36
        this.remaining = initialSize;
37 1 1. <init> : removed call to java/util/List::forEach → TIMED_OUT
        futures.forEach(f -> f.whenComplete((__, ___) -> completed.add(f)));
38
    }
39
40
    @Override
41
    public boolean tryAdvance(Consumer<? super T> action) {
42 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
43 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()
44
          : false;
45
    }
46
47
    private CompletableFuture<T> nextCompleted() {
48
        try {
49
            var next = completed.take();
50 1 1. nextCompleted : Replaced integer subtraction with addition → TIMED_OUT
            remaining--;
51 1 1. nextCompleted : replaced return value with null for com/pivovarit/collectors/CompletionOrderSpliterator::nextCompleted → KILLED
            return next;
52
        } catch (InterruptedException e) {
53 1 1. nextCompleted : removed call to java/lang/Thread::interrupt → TIMED_OUT
            Thread.currentThread().interrupt();
54
55
            throw new RuntimeException(e);
56
        }
57
    }
58
59
    @Override
60
    public Spliterator<T> trySplit() {
61
        return null;
62
    }
63
64
    @Override
65
    public long estimateSize() {
66 1 1. estimateSize : replaced long return with 0 for com/pivovarit/collectors/CompletionOrderSpliterator::estimateSize → KILLED
        return initialSize;
67
    }
68
69
    @Override
70
    public int characteristics() {
71 1 1. characteristics : replaced int return with 0 for com/pivovarit/collectors/CompletionOrderSpliterator::characteristics → SURVIVED
        return SIZED | IMMUTABLE | NONNULL;
72
    }
73
}

Mutations

37

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

42

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

43

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

50

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

51

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

53

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

66

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

71

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.22.0