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 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 13.13 |
|
48 |
1.1 |
|
51 |
1.1 |
|
55 |
1.1 2.2 |
|
56 |
1.1 2.2 3.3 |
|
57 |
1.1 2.2 |
|
61 |
1.1 |
|
65 |
1.1 2.2 |