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.WordprocessingML.CommentsPart; | |
6 | import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; | |
7 | import org.docx4j.relationships.Relationship; | |
8 | import org.docx4j.wml.ContentAccessor; | |
9 | import org.docx4j.wml.P; | |
10 | import pro.verron.officestamper.api.DocxPart; | |
11 | ||
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, | |
28 | Part part, | |
29 | ContentAccessor contentAccessor | |
30 | ) { | |
31 | this.document = document; | |
32 | this.part = part; | |
33 | this.contentAccessor = contentAccessor; | |
34 | } | |
35 | ||
36 | public Stream<P> streamParagraphs() { | |
37 |
1
1. streamParagraphs : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParagraphs → KILLED |
return DocumentUtil.streamObjectElements(this, P.class); |
38 | } | |
39 | ||
40 | public Stream<DocxPart> streamParts(String type) { | |
41 |
1
1. streamParts : replaced return value with Stream.empty for pro/verron/officestamper/core/TextualDocxPart::streamParts → KILLED |
return document.getMainDocumentPart() |
42 | .getRelationshipsPart() | |
43 | .getRelationshipsByType(type) | |
44 | .stream() | |
45 | .map(this::getPart) | |
46 |
1
1. lambda$streamParts$0 : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::lambda$streamParts$0 → KILLED |
.map(p -> new TextualDocxPart(document, p, (ContentAccessor) p)); |
47 | } | |
48 | ||
49 | public Part getPart(Relationship r) { | |
50 |
1
1. getPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getPart → KILLED |
return getRelationshipsPart().getPart(r); |
51 | } | |
52 | ||
53 |
1
1. document : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::document → KILLED |
public WordprocessingMLPackage document() {return document;} |
54 | ||
55 | private RelationshipsPart getRelationshipsPart() { | |
56 |
1
1. getRelationshipsPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::getRelationshipsPart → KILLED |
return part().getRelationshipsPart(); |
57 | } | |
58 | ||
59 | public CommentsPart commentsPart() { | |
60 |
1
1. commentsPart : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::commentsPart → KILLED |
return CommentUtil.getCommentsPart(document.getParts()); |
61 | } | |
62 | ||
63 | @Override public DocxPart from(ContentAccessor accessor) { | |
64 |
1
1. from : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::from → KILLED |
return new TextualDocxPart(document, part, accessor); |
65 | } | |
66 | ||
67 |
1
1. part : replaced return value with null for pro/verron/officestamper/core/TextualDocxPart::part → KILLED |
@Override public Part part() {return part;} |
68 | ||
69 |
1
1. content : replaced return value with Collections.emptyList for pro/verron/officestamper/core/TextualDocxPart::content → KILLED |
@Override public List<Object> content() {return contentAccessor.getContent();} |
70 | ||
71 | @Override | |
72 | public int hashCode() { | |
73 |
1
1. hashCode : replaced int return with 0 for pro/verron/officestamper/core/TextualDocxPart::hashCode → NO_COVERAGE |
return Objects.hash(document, part, contentAccessor); |
74 | } | |
75 | ||
76 | @Override | |
77 | public boolean equals(Object obj) { | |
78 |
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; |
79 |
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; |
80 | var that = (TextualDocxPart) obj; | |
81 |
2
1. equals : replaced boolean return with true for pro/verron/officestamper/core/TextualDocxPart::equals → NO_COVERAGE 2. equals : negated conditional → NO_COVERAGE |
return Objects.equals(this.document, that.document) && |
82 |
1
1. equals : negated conditional → NO_COVERAGE |
Objects.equals(this.part, that.part) && |
83 |
1
1. equals : negated conditional → NO_COVERAGE |
Objects.equals(this.contentAccessor, that.contentAccessor); |
84 | } | |
85 | ||
86 | @Override public String toString() { | |
87 |
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()); |
88 | } | |
89 | ||
90 | } | |
Mutations | ||
37 |
1.1 |
|
41 |
1.1 |
|
46 |
1.1 |
|
50 |
1.1 |
|
53 |
1.1 |
|
56 |
1.1 |
|
60 |
1.1 |
|
64 |
1.1 |
|
67 |
1.1 |
|
69 |
1.1 |
|
73 |
1.1 |
|
78 |
1.1 2.2 |
|
79 |
1.1 2.2 3.3 |
|
81 |
1.1 2.2 |
|
82 |
1.1 |
|
83 |
1.1 |
|
87 |
1.1 |