PowerpointRun.java

1
package pro.verron.officestamper.experimental;
2
3
import org.docx4j.dml.CTRegularTextRun;
4
5
/// A record that represents a run of text in a PowerPoint slide. It holds information
6
/// about the run's indices and the underlying text content. The indices define the
7
/// range of the text run within a global context, and the backing content is stored
8
/// as a `CTRegularTextRun` instance from the supporting library.
9
///
10
/// This class provides methods to determine if a text run is affected by a global range
11
/// of indices and to replace specific substrings within its text.
12
///
13
/// @param startIndex the start index of the run within the global context.
14
/// @param endIndex   the end index of the run within the global context.
15
/// @param indexInParent the index of the run within its parent paragraph.
16
/// @param run the underlying `CTRegularTextRun` instance.
17
public record PowerpointRun(
18
        int startIndex,
19
        int endIndex,
20
        int indexInParent,
21
        CTRegularTextRun run
22
) {
23
    /// Checks if the given range of indices touches the start or end index of the run.
24
    ///
25
    /// @param globalStartIndex the start index of the global range.
26
    /// @param globalEndIndex   the end index of the global range.
27
    ///
28
    /// @return `true` if the range touches the start or end index of the run, `false` otherwise.
29
    public boolean isTouchedByRange(int globalStartIndex, int globalEndIndex) {
30 13 1. isTouchedByRange : changed conditional boundary → SURVIVED
2. isTouchedByRange : negated conditional → NO_COVERAGE
3. isTouchedByRange : changed conditional boundary → SURVIVED
4. isTouchedByRange : changed conditional boundary → NO_COVERAGE
5. isTouchedByRange : negated conditional → NO_COVERAGE
6. isTouchedByRange : negated conditional → NO_COVERAGE
7. isTouchedByRange : negated conditional → SURVIVED
8. isTouchedByRange : negated conditional → SURVIVED
9. isTouchedByRange : replaced boolean return with true for pro/verron/officestamper/experimental/PowerpointRun::isTouchedByRange → SURVIVED
10. isTouchedByRange : changed conditional boundary → NO_COVERAGE
11. isTouchedByRange : negated conditional → NO_COVERAGE
12. isTouchedByRange : changed conditional boundary → NO_COVERAGE
13. isTouchedByRange : changed conditional boundary → NO_COVERAGE
        return ((startIndex >= globalStartIndex) && (startIndex <= globalEndIndex))
31
                || ((endIndex >= globalStartIndex) && (endIndex <= globalEndIndex))
32
                || ((startIndex <= globalStartIndex) && (endIndex >= globalEndIndex));
33
    }
34
35
    /// Replaces a substring within the run's text.
36
    ///
37
    /// @param globalStartIndex the start index of the substring to be replaced.
38
    /// @param globalEndIndex   the end index of the substring to be replaced.
39
    /// @param replacement      the replacement string.
40
    public void replace(
41
            int globalStartIndex,
42
            int globalEndIndex,
43
            String replacement
44
    ) {
45
        int localStartIndex = globalIndexToLocalIndex(globalStartIndex);
46
        int localEndIndex = globalIndexToLocalIndex(globalEndIndex);
47
        var source = run.getT();
48 1 1. replace : Replaced integer addition with subtraction → KILLED
        var target = source.substring(0, localStartIndex)
49
                + replacement
50
                + source.substring(localEndIndex + 1);
51 1 1. replace : removed call to org/docx4j/dml/CTRegularTextRun::setT → KILLED
        run.setT(target);
52
    }
53
54
    private int globalIndexToLocalIndex(int globalIndex) {
55 2 1. globalIndexToLocalIndex : changed conditional boundary → SURVIVED
2. globalIndexToLocalIndex : negated conditional → KILLED
        if (globalIndex < startIndex) return 0;
56 3 1. globalIndexToLocalIndex : changed conditional boundary → SURVIVED
2. globalIndexToLocalIndex : replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::globalIndexToLocalIndex → KILLED
3. globalIndexToLocalIndex : negated conditional → KILLED
        else if (globalIndex > endIndex) return lastIndex();
57 2 1. globalIndexToLocalIndex : replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::globalIndexToLocalIndex → SURVIVED
2. globalIndexToLocalIndex : Replaced integer subtraction with addition → KILLED
        else return globalIndex - startIndex;
58
    }
59
60
    private int lastIndex() {
61 1 1. lastIndex : replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::lastIndex → KILLED
        return lastIndex(run.getT());
62
    }
63
64
    private int lastIndex(String string) {
65 2 1. lastIndex : Replaced integer subtraction with addition → KILLED
2. lastIndex : replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::lastIndex → KILLED
        return string.length() - 1;
66
    }
67
}

Mutations

30

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

2.2
Location : isTouchedByRange
Killed by : none
negated conditional → NO_COVERAGE

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

4.4
Location : isTouchedByRange
Killed by : none
changed conditional boundary → NO_COVERAGE

5.5
Location : isTouchedByRange
Killed by : none
negated conditional → NO_COVERAGE

6.6
Location : isTouchedByRange
Killed by : none
negated conditional → NO_COVERAGE

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

8.8
Location : isTouchedByRange
Killed by : none
negated conditional → SURVIVED Covering tests

9.9
Location : isTouchedByRange
Killed by : none
replaced boolean return with true for pro/verron/officestamper/experimental/PowerpointRun::isTouchedByRange → SURVIVED Covering tests

10.10
Location : isTouchedByRange
Killed by : none
changed conditional boundary → NO_COVERAGE

11.11
Location : isTouchedByRange
Killed by : none
negated conditional → NO_COVERAGE

12.12
Location : isTouchedByRange
Killed by : none
changed conditional boundary → NO_COVERAGE

13.13
Location : isTouchedByRange
Killed by : none
changed conditional boundary → NO_COVERAGE

48

1.1
Location : replace
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
Replaced integer addition with subtraction → KILLED

51

1.1
Location : replace
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
removed call to org/docx4j/dml/CTRegularTextRun::setT → KILLED

55

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

2.2
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
negated conditional → KILLED

56

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

2.2
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::globalIndexToLocalIndex → KILLED

3.3
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
negated conditional → KILLED

57

1.1
Location : globalIndexToLocalIndex
Killed by : none
replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::globalIndexToLocalIndex → SURVIVED
Covering tests

2.2
Location : globalIndexToLocalIndex
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
Replaced integer subtraction with addition → KILLED

61

1.1
Location : lastIndex
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::lastIndex → KILLED

65

1.1
Location : lastIndex
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
Replaced integer subtraction with addition → KILLED

2.2
Location : lastIndex
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::lastIndex → KILLED

Active mutators

Tests examined


Report generated by PIT 1.21.0