IndexedRun.java

1
package pro.verron.officestamper.core;
2
3
import org.docx4j.wml.R;
4
import org.docx4j.wml.RPr;
5
6
/**
7
 * Represents a run (i.e., a text fragment) in a paragraph. The run is indexed relative to the containing paragraph
8
 * and also relative to the containing document.
9
 *
10
 * @param startIndex    the start index of the run relative to the containing paragraph.
11
 * @param endIndex      the end index of the run relative to the containing paragraph.
12
 * @param indexInParent the index of the run relative to the containing document.
13
 * @param run           the run itself.
14
 *
15
 * @author Joseph Verron
16
 * @author Tom Hombergs
17
 * @version ${version}
18
 * @since 1.0.0
19
 */
20
public record IndexedRun(int startIndex, int endIndex, int indexInParent, R run) {
21
22
    public int length() {
23 1 1. length : replaced int return with 0 for pro/verron/officestamper/core/IndexedRun::length → SURVIVED
        return getText().length();
24
    }
25
26
    public String getText() {
27 1 1. getText : replaced return value with "" for pro/verron/officestamper/core/IndexedRun::getText → KILLED
        return RunUtil.getText(run());
28
    }
29
30
    public String substring(int endIndex) {
31 1 1. substring : replaced return value with "" for pro/verron/officestamper/core/IndexedRun::substring → KILLED
        return getText().substring(endIndex);
32
    }
33
34
    public String substring(int beginIndex, int endIndex) {
35 1 1. substring : replaced return value with "" for pro/verron/officestamper/core/IndexedRun::substring → KILLED
        return getText().substring(beginIndex, endIndex);
36
    }
37
38
    public int indexOf(String full) {
39 1 1. indexOf : replaced int return with 0 for pro/verron/officestamper/core/IndexedRun::indexOf → KILLED
        return getText().indexOf(full);
40
    }
41
42
    public RPr getPr() {
43 1 1. getPr : replaced return value with null for pro/verron/officestamper/core/IndexedRun::getPr → KILLED
        return run.getRPr();
44
    }
45
46
    /**
47
     * Determines whether the specified range of start and end index touches this run.
48
     * <p>
49
     * Example:
50
     * <p>
51
     * Given this run: [a,b,c,d,e,f,g,h,i,j]
52
     * <p>
53
     * And the range [2,5]
54
     * <p>
55
     * This method will return true, because the range touches the run at the indices 2, 3, 4 and 5.
56
     *
57
     * @param globalStartIndex the global index (meaning the index relative to multiple aggregated runs) at which to
58
     *                         start the range.
59
     * @param globalEndIndex   the global index (meaning the index relative to multiple aggregated runs) at which to end
60
     *                         the range.
61
     *
62
     * @return true, if the range touches this run, false otherwise.
63
     */
64
    public boolean isTouchedByRange(int globalStartIndex, int globalEndIndex) {
65 4 1. isTouchedByRange : changed conditional boundary → SURVIVED
2. isTouchedByRange : negated conditional → KILLED
3. isTouchedByRange : negated conditional → KILLED
4. isTouchedByRange : changed conditional boundary → KILLED
        var startBetweenIndices = (globalStartIndex < startIndex) && (startIndex <= globalEndIndex);
66 4 1. isTouchedByRange : changed conditional boundary → SURVIVED
2. isTouchedByRange : negated conditional → KILLED
3. isTouchedByRange : changed conditional boundary → KILLED
4. isTouchedByRange : negated conditional → KILLED
        var endBetweenIndices = (globalStartIndex < endIndex) && (endIndex <= globalEndIndex);
67 7 1. isTouchedByRange : changed conditional boundary → SURVIVED
2. isTouchedByRange : changed conditional boundary → SURVIVED
3. isTouchedByRange : negated conditional → KILLED
4. isTouchedByRange : negated conditional → KILLED
5. isTouchedByRange : negated conditional → KILLED
6. isTouchedByRange : negated conditional → KILLED
7. isTouchedByRange : replaced boolean return with true for pro/verron/officestamper/core/IndexedRun::isTouchedByRange → KILLED
        return startBetweenIndices
68
               || endBetweenIndices
69
               || ((startIndex <= globalStartIndex)
70
                   && (globalEndIndex <= endIndex));
71
    }
72
73
    /**
74
     * Replaces the substring starting at the given index with the given replacement string.
75
     *
76
     * @param globalStartIndex the global index at which to
77
     *                         start the replacement.
78
     * @param globalEndIndex   the global index at which to end
79
     *                         the replacement.
80
     * @param replacement      the string to replace the substring at the specified global index.
81
     */
82
    public void replace(int globalStartIndex, int globalEndIndex, String replacement) {
83
        int localStartIndex = globalIndexToLocalIndex(globalStartIndex);
84
        int localEndIndex = globalIndexToLocalIndex(globalEndIndex);
85
        var text = RunUtil.getSubstring(run, 0, localStartIndex);
86
        text += replacement;
87
        String runText = RunUtil.getText(run);
88 1 1. replace : negated conditional → KILLED
        if (!runText.isEmpty()) {
89
            text += RunUtil.getSubstring(run, localEndIndex);
90
        }
91 1 1. replace : removed call to pro/verron/officestamper/core/RunUtil::setText → KILLED
        RunUtil.setText(run, text);
92
    }
93
94
    /**
95
     * Converts a global index to a local index within the context of this run.
96
     * (meaning the index relative to multiple aggregated runs)
97
     *
98
     * @param globalIndex the global index to convert.
99
     *
100
     * @return the local index corresponding to the given global index.
101
     */
102
    private int globalIndexToLocalIndex(int globalIndex) {
103 2 1. globalIndexToLocalIndex : changed conditional boundary → SURVIVED
2. globalIndexToLocalIndex : negated conditional → KILLED
        if (globalIndex < startIndex) return 0;
104 3 1. globalIndexToLocalIndex : changed conditional boundary → SURVIVED
2. globalIndexToLocalIndex : negated conditional → KILLED
3. globalIndexToLocalIndex : replaced int return with 0 for pro/verron/officestamper/core/IndexedRun::globalIndexToLocalIndex → KILLED
        else if (globalIndex > endIndex) return RunUtil.getLength(run);
105 2 1. globalIndexToLocalIndex : Replaced integer subtraction with addition → KILLED
2. globalIndexToLocalIndex : replaced int return with 0 for pro/verron/officestamper/core/IndexedRun::globalIndexToLocalIndex → KILLED
        else return globalIndex - startIndex;
106
    }
107
}

Mutations

23

1.1
Location : length
Killed by : none
replaced int return with 0 for pro/verron/officestamper/core/IndexedRun::length → SURVIVED
Covering tests

27

1.1
Location : getText
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#25]
replaced return value with "" for pro/verron/officestamper/core/IndexedRun::getText → KILLED

31

1.1
Location : substring
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#25]
replaced return value with "" for pro/verron/officestamper/core/IndexedRun::substring → KILLED

35

1.1
Location : substring
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#25]
replaced return value with "" for pro/verron/officestamper/core/IndexedRun::substring → KILLED

39

1.1
Location : indexOf
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#25]
replaced int return with 0 for pro/verron/officestamper/core/IndexedRun::indexOf → KILLED

43

1.1
Location : getPr
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#28]
replaced return value with null for pro/verron/officestamper/core/IndexedRun::getPr → KILLED

65

1.1
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#16]
negated conditional → KILLED

2.2
Location : isTouchedByRange
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

3.3
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#29]
negated conditional → KILLED

4.4
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#6]
changed conditional boundary → KILLED

66

1.1
Location : isTouchedByRange
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

2.2
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#28]
negated conditional → KILLED

3.3
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#28]
changed conditional boundary → KILLED

4.4
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#28]
negated conditional → KILLED

67

1.1
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#16]
negated conditional → KILLED

2.2
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#25]
negated conditional → KILLED

3.3
Location : isTouchedByRange
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

4.4
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#28]
negated conditional → KILLED

5.5
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#25]
negated conditional → KILLED

6.6
Location : isTouchedByRange
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#16]
replaced boolean return with true for pro/verron/officestamper/core/IndexedRun::isTouchedByRange → KILLED

7.7
Location : isTouchedByRange
Killed by : none
changed conditional boundary → SURVIVED Covering tests

88

1.1
Location : replace
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#16]
negated conditional → KILLED

91

1.1
Location : replace
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#28]
removed call to pro/verron/officestamper/core/RunUtil::setText → KILLED

103

1.1
Location : globalIndexToLocalIndex
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

2.2
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#28]
negated conditional → KILLED

104

1.1
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#28]
negated conditional → KILLED

2.2
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#32]
replaced int return with 0 for pro/verron/officestamper/core/IndexedRun::globalIndexToLocalIndex → KILLED

3.3
Location : globalIndexToLocalIndex
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

105

1.1
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#28]
Replaced integer subtraction with addition → KILLED

2.2
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#28]
replaced int return with 0 for pro/verron/officestamper/core/IndexedRun::globalIndexToLocalIndex → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1