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
    /// @return `true` if the range touches the start or end index of the run, `false` otherwise.
28
    public boolean isTouchedByRange(int globalStartIndex, int globalEndIndex) {
29 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))
30
                || ((endIndex >= globalStartIndex) && (endIndex <= globalEndIndex))
31
                || ((startIndex <= globalStartIndex) && (endIndex >= globalEndIndex));
32
    }
33
34
    /// Replaces a substring within the run's text.
35
    ///
36
    /// @param globalStartIndex the start index of the substring to be replaced.
37
    /// @param globalEndIndex   the end index of the substring to be replaced.
38
    /// @param replacement      the replacement string.
39
    public void replace(
40
            int globalStartIndex,
41
            int globalEndIndex,
42
            String replacement
43
    ) {
44
        int localStartIndex = globalIndexToLocalIndex(globalStartIndex);
45
        int localEndIndex = globalIndexToLocalIndex(globalEndIndex);
46
        var source = run.getT();
47 1 1. replace : Replaced integer addition with subtraction → KILLED
        var target = source.substring(0, localStartIndex)
48
                + replacement
49
                + source.substring(localEndIndex + 1);
50 1 1. replace : removed call to org/docx4j/dml/CTRegularTextRun::setT → KILLED
        run.setT(target);
51
    }
52
53
    private int globalIndexToLocalIndex(int globalIndex) {
54 2 1. globalIndexToLocalIndex : changed conditional boundary → SURVIVED
2. globalIndexToLocalIndex : negated conditional → KILLED
        if (globalIndex < startIndex) return 0;
55 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();
56 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;
57
    }
58
59
    private int lastIndex() {
60 1 1. lastIndex : replaced int return with 0 for pro/verron/officestamper/experimental/PowerpointRun::lastIndex → KILLED
        return lastIndex(run.getT());
61
    }
62
63
    private int lastIndex(String string) {
64 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;
65
    }
66
}

Mutations

29

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

47

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

50

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

54

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

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()]
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

56

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

60

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

64

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.25.5 support