WindowSlidingGatherer.java

1
package com.pivovarit.gatherers;
2
3
import java.util.Arrays;
4
import java.util.List;
5
import java.util.function.BiConsumer;
6
import java.util.function.Supplier;
7
import java.util.stream.Gatherer;
8
9
record WindowSlidingGatherer<T>(int windowSize, int step)
10
  implements Gatherer<T, WindowSlidingGatherer.SlidingWindow, List<T>> {
11
    WindowSlidingGatherer {
12
        if (windowSize < 1) {
13
            throw new IllegalArgumentException("'windowSize' must be greater than zero");
14
        }
15
16
        if (step < 0) {
17
            throw new IllegalArgumentException("'step' must be greater than or equal to zero");
18
        }
19
20
        if (step > windowSize) {
21
            throw new IllegalArgumentException("'step' must be less than or equal to 'windowSize'");
22
        }
23
    }
24
25
    @Override
26
    public Supplier<WindowSlidingGatherer.SlidingWindow> initializer() {
27 2 1. lambda$initializer$0 : replaced return value with null for com/pivovarit/gatherers/WindowSlidingGatherer::lambda$initializer$0 → KILLED
2. initializer : replaced return value with null for com/pivovarit/gatherers/WindowSlidingGatherer::initializer → KILLED
        return WindowSlidingGatherer.SlidingWindow::new;
28
    }
29
30
    @Override
31
    public Integrator<WindowSlidingGatherer.SlidingWindow, T, List<T>> integrator() {
32 3 1. lambda$integrator$1 : replaced boolean return with true for com/pivovarit/gatherers/WindowSlidingGatherer::lambda$integrator$1 → SURVIVED
2. lambda$integrator$1 : replaced boolean return with false for com/pivovarit/gatherers/WindowSlidingGatherer::lambda$integrator$1 → SURVIVED
3. integrator : replaced return value with null for com/pivovarit/gatherers/WindowSlidingGatherer::integrator → KILLED
        return Integrator.ofGreedy((state, e, downstream) -> state.integrate(e, downstream));
33
    }
34
35
    @Override
36
    public BiConsumer<WindowSlidingGatherer.SlidingWindow, Downstream<? super List<T>>> finisher() {
37 1 1. finisher : replaced return value with null for com/pivovarit/gatherers/WindowSlidingGatherer::finisher → KILLED
        return SlidingWindow::finish;
38
    }
39
40
    class SlidingWindow {
41
        private Object[] window = new Object[windowSize];
42
        private int at = 0;
43
        private boolean emitted = false;
44
45
        boolean integrate(T element, Downstream<? super List<T>> downstream) {
46 1 1. integrate : Replaced integer addition with subtraction → KILLED
            window[at++] = element;
47
            emitted = false;
48 2 1. integrate : negated conditional → KILLED
2. integrate : changed conditional boundary → KILLED
            if (at < windowSize) {
49 1 1. integrate : replaced boolean return with false for com/pivovarit/gatherers/WindowSlidingGatherer$SlidingWindow::integrate → SURVIVED
                return true;
50
            } else {
51
                final var oldWindow = window;
52
                final var newWindow = new Object[windowSize];
53 2 1. integrate : Replaced integer subtraction with addition → KILLED
2. integrate : removed call to java/lang/System::arraycopy → KILLED
                System.arraycopy(oldWindow, step, newWindow, 0, windowSize - step);
54
                window = newWindow;
55 1 1. integrate : Replaced integer subtraction with addition → KILLED
                at -= step;
56
                emitted = true;
57 2 1. integrate : replaced boolean return with true for com/pivovarit/gatherers/WindowSlidingGatherer$SlidingWindow::integrate → SURVIVED
2. integrate : replaced boolean return with false for com/pivovarit/gatherers/WindowSlidingGatherer$SlidingWindow::integrate → SURVIVED
                return downstream.push((List<T>) Arrays.asList(oldWindow));
58
            }
59
        }
60
61
        void finish(Downstream<? super List<T>> downstream) {
62 4 1. finish : negated conditional → KILLED
2. finish : changed conditional boundary → KILLED
3. finish : negated conditional → KILLED
4. finish : negated conditional → KILLED
            if (!emitted && at > 0 && !downstream.isRejecting()) {
63
                var lastWindow = new Object[at];
64 1 1. finish : removed call to java/lang/System::arraycopy → KILLED
                System.arraycopy(window, 0, lastWindow, 0, at);
65
                window = null;
66
                at = 0;
67
                emitted = true;
68
                downstream.push((List<T>) Arrays.asList(lastWindow));
69
            }
70
        }
71
    }
72
}

Mutations

27

1.1
Location : lambda$initializer$0
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingEmpty()]
replaced return value with null for com/pivovarit/gatherers/WindowSlidingGatherer::lambda$initializer$0 → KILLED

2.2
Location : initializer
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingEmpty()]
replaced return value with null for com/pivovarit/gatherers/WindowSlidingGatherer::initializer → KILLED

32

1.1
Location : lambda$integrator$1
Killed by : none
replaced boolean return with true for com/pivovarit/gatherers/WindowSlidingGatherer::lambda$integrator$1 → SURVIVED
Covering tests

2.2
Location : integrator
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithStep1()]
replaced return value with null for com/pivovarit/gatherers/WindowSlidingGatherer::integrator → KILLED

3.3
Location : lambda$integrator$1
Killed by : none
replaced boolean return with false for com/pivovarit/gatherers/WindowSlidingGatherer::lambda$integrator$1 → SURVIVED Covering tests

37

1.1
Location : finisher
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingEmpty()]
replaced return value with null for com/pivovarit/gatherers/WindowSlidingGatherer::finisher → KILLED

46

1.1
Location : integrate
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithStep1()]
Replaced integer addition with subtraction → KILLED

48

1.1
Location : integrate
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithStep1()]
negated conditional → KILLED

2.2
Location : integrate
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithStep1()]
changed conditional boundary → KILLED

49

1.1
Location : integrate
Killed by : none
replaced boolean return with false for com/pivovarit/gatherers/WindowSlidingGatherer$SlidingWindow::integrate → SURVIVED
Covering tests

53

1.1
Location : integrate
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithStep1()]
Replaced integer subtraction with addition → KILLED

2.2
Location : integrate
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithStep1()]
removed call to java/lang/System::arraycopy → KILLED

55

1.1
Location : integrate
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithStep1()]
Replaced integer subtraction with addition → KILLED

57

1.1
Location : integrate
Killed by : none
replaced boolean return with true for com/pivovarit/gatherers/WindowSlidingGatherer$SlidingWindow::integrate → SURVIVED
Covering tests

2.2
Location : integrate
Killed by : none
replaced boolean return with false for com/pivovarit/gatherers/WindowSlidingGatherer$SlidingWindow::integrate → SURVIVED Covering tests

62

1.1
Location : finish
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingEmpty()]
negated conditional → KILLED

2.2
Location : finish
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingEmpty()]
changed conditional boundary → KILLED

3.3
Location : finish
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithStep1()]
negated conditional → KILLED

4.4
Location : finish
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithWindowSizeGreaterThanStreamSize()]
negated conditional → KILLED

64

1.1
Location : finish
Killed by : com.pivovarit.gatherers.blackbox.WindowSlidingTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.WindowSlidingTest]/[method:shouldWindowSlidingWithWindowSizeGreaterThanStreamSize()]
removed call to java/lang/System::arraycopy → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1