1 | package pro.verron.officestamper.experimental; | |
2 | ||
3 | import org.xlsx4j.sml.CTRst; | |
4 | import pro.verron.officestamper.api.Placeholder; | |
5 | ||
6 | /// The ExcelParagraph class represents a paragraph in an Excel document. | |
7 | /// It provides methods to replace expressions and retrieve the aggregated text over all runs. | |
8 | public class ExcelParagraph { | |
9 | private final CTRst paragraph; | |
10 | ||
11 | /// Constructs a new ParagraphWrapper for the given paragraph. | |
12 | /// | |
13 | /// @param paragraph the paragraph to wrap. | |
14 | public ExcelParagraph(CTRst paragraph) { | |
15 | this.paragraph = paragraph; | |
16 | } | |
17 | ||
18 | /// Replaces the given expression with the replacement object within | |
19 | /// the paragraph. | |
20 | /// The replacement object must be a valid DOCX4J Object. | |
21 | /// | |
22 | /// @param placeholder the expression to be replaced. | |
23 | /// @param replacement the object to replace the expression. | |
24 | public void replace(Placeholder placeholder, String replacement) { | |
25 | var ctXstringWhitespace = paragraph.getT(); | |
26 | var string = ctXstringWhitespace.getValue(); | |
27 | var start = string.indexOf(placeholder.expression()); | |
28 | var end = start + placeholder.expression() | |
29 |
1
1. replace : Replaced integer addition with subtraction → KILLED |
.length(); |
30 | var next = string.substring(0, start) + replacement + string.substring(end); | |
31 |
1
1. replace : removed call to org/xlsx4j/sml/CTXstringWhitespace::setValue → KILLED |
ctXstringWhitespace.setValue(next); |
32 | } | |
33 | ||
34 | /// {@inheritDoc} | |
35 | @Override | |
36 | public String toString() { | |
37 |
1
1. toString : replaced return value with "" for pro/verron/officestamper/experimental/ExcelParagraph::toString → NO_COVERAGE |
return asString(); |
38 | } | |
39 | ||
40 | /// Returns the aggregated text over all runs. | |
41 | /// | |
42 | /// @return the text of all runs. | |
43 | public String asString() { | |
44 |
1
1. asString : replaced return value with "" for pro/verron/officestamper/experimental/ExcelParagraph::asString → KILLED |
return paragraph.getR() + ": " + paragraph.getT() |
45 | .getValue(); | |
46 | } | |
47 | } | |
Mutations | ||
29 |
1.1 |
|
31 |
1.1 |
|
37 |
1.1 |
|
44 |
1.1 |