1 | package pro.verron.officestamper.core; | |
2 | ||
3 | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; | |
4 | import org.docx4j.openpackaging.parts.Part; | |
5 | import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; | |
6 | import org.docx4j.relationships.Relationship; | |
7 | import org.docx4j.wml.*; | |
8 | import pro.verron.officestamper.api.DocxPart; | |
9 | import pro.verron.officestamper.api.Paragraph; | |
10 | ||
11 | import java.util.Collection; | |
12 | import java.util.List; | |
13 | import java.util.Objects; | |
14 | import java.util.stream.Stream; | |
15 | ||
16 | public final class TextualDocxPart | |
17 | implements DocxPart { | |
18 | private final WordprocessingMLPackage document; | |
19 | private final Part part; | |
20 | private final ContentAccessor contentAccessor; | |
21 | ||
22 | public TextualDocxPart(WordprocessingMLPackage document) { | |
23 | this(document, document.getMainDocumentPart(), document.getMainDocumentPart()); | |
24 | } | |
25 | ||
26 | public TextualDocxPart( | |
27 | WordprocessingMLPackage document, Part part, ContentAccessor contentAccessor | |
28 | ) { | |
29 | this.document = document; | |
30 | this.part = part; | |
31 | this.contentAccessor = contentAccessor; | |
32 | } | |
33 | ||
34 | ||
35 | public Stream<Paragraph> streamParagraphs() { | |
36 |
1
1. streamParagraphs : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParagraphs → KILLED |
return Stream.concat(DocumentUtil.streamObjectElements(this, P.class) |
37 |
1
1. lambda$streamParagraphs$0 : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParagraphs$0 → KILLED |
.map(p -> StandardParagraph.from(this, p)), |
38 | DocumentUtil.streamObjectElements(this, SdtRun.class) | |
39 | .map(SdtRun::getSdtContent) | |
40 | .filter(CTSdtContentRun.class::isInstance) | |
41 | .map(CTSdtContentRun.class::cast) | |
42 |
1
1. lambda$streamParagraphs$1 : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParagraphs$1 → KILLED |
.map(paragraph -> StandardParagraph.from(this, paragraph))); |
43 | } | |
44 | ||
45 | @Override public Stream<R> streamRun() { | |
46 |
1
1. streamRun : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamRun → KILLED |
return DocumentUtil.streamObjectElements(this, P.class) |
47 | .map(P::getContent) | |
48 | .flatMap(Collection::stream) | |
49 | .filter(R.class::isInstance) | |
50 | .map(R.class::cast); | |
51 | } | |
52 | ||
53 | ||
54 | public Stream<DocxPart> streamParts(String type) { | |
55 |
1
1. streamParts : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParts → KILLED |
return document.getMainDocumentPart() |
56 | .getRelationshipsPart() | |
57 | .getRelationshipsByType(type) | |
58 | .stream() | |
59 | .map(this::getPart) | |
60 |
1
1. lambda$streamParts$2 : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParts$2 → KILLED |
.map(p -> new TextualDocxPart(document, p, (ContentAccessor) p)); |
61 | } | |
62 | ||
63 | public Part getPart(Relationship r) { | |
64 |
1
1. getPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getPart → KILLED |
return getRelationshipsPart().getPart(r); |
65 | } | |
66 | ||
67 |
1
1. document : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::document → KILLED |
public WordprocessingMLPackage document() {return document;} |
68 | private RelationshipsPart getRelationshipsPart() { | |
69 |
1
1. getRelationshipsPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getRelationshipsPart → KILLED |
return part().getRelationshipsPart(); |
70 | } | |
71 | ||
72 | ||
73 | ||
74 | @Override public DocxPart from(ContentAccessor accessor) { | |
75 |
1
1. from : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::from → NO_COVERAGE |
return new TextualDocxPart(document, part, accessor); |
76 | } | |
77 | ||
78 |
1
1. part : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::part → KILLED |
@Override public Part part() {return part;} |
79 | ||
80 |
1
1. content : replaced return value with Collections.emptyList for pro/verron/officestamper/core/TextualDocxPart::content → NO_COVERAGE |
@Override public List<Object> content() {return contentAccessor.getContent();} |
81 | ||
82 | ||
83 | @Override public int hashCode() { | |
84 |
1
1. hashCode : replaced int return with 0 for pro/verron/officestamper/core/TextualDocxPart::hashCode → NO_COVERAGE |
return Objects.hash(document, part, contentAccessor); |
85 | } | |
86 | ||
87 | @Override public boolean equals(Object obj) { | |
88 |
2
1. equals : replaced boolean return with false for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE 2. equals : negated conditional → NO_COVERAGE |
if (obj == this) return true; |
89 |
3
1. equals : negated conditional → NO_COVERAGE 2. equals : negated conditional → NO_COVERAGE 3. equals : replaced boolean return with true for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE |
if (obj == null || obj.getClass() != this.getClass()) return false; |
90 | var that = (TextualDocxPart) obj; | |
91 |
4
1. equals : negated conditional → NO_COVERAGE 2. equals : negated conditional → NO_COVERAGE 3. equals : replaced boolean return with true for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE 4. equals : negated conditional → NO_COVERAGE |
return Objects.equals(this.document, that.document) && Objects.equals(this.part, that.part) && Objects.equals( |
92 | this.contentAccessor, | |
93 | that.contentAccessor); | |
94 | } | |
95 | ||
96 | @Override public String toString() { | |
97 |
1
1. toString : replaced return value with "" for pro/verron/officestamper/core/TextualDocxPart::toString → NO_COVERAGE |
return "DocxPart{doc=%s, part=%s}".formatted(document.name(), part.getPartName()); |
98 | } | |
99 | ||
100 | } | |
Mutations | ||
36 |
1.1 |
|
37 |
1.1 |
|
42 |
1.1 |
|
46 |
1.1 |
|
55 |
1.1 |
|
60 |
1.1 |
|
64 |
1.1 |
|
67 |
1.1 |
|
69 |
1.1 |
|
75 |
1.1 |
|
78 |
1.1 |
|
80 |
1.1 |
|
84 |
1.1 |
|
88 |
1.1 2.2 |
|
89 |
1.1 2.2 3.3 |
|
91 |
1.1 2.2 3.3 4.4 |
|
97 |
1.1 |