1 | package pro.verron.officestamper.core; | |
2 | ||
3 | import org.docx4j.TextUtils; | |
4 | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; | |
5 | import org.docx4j.wml.*; | |
6 | import org.docx4j.wml.R.CommentReference; | |
7 | import pro.verron.officestamper.api.Comment; | |
8 | import pro.verron.officestamper.api.Placeholder; | |
9 | ||
10 | import java.math.BigInteger; | |
11 | import java.util.ArrayList; | |
12 | import java.util.HashSet; | |
13 | import java.util.List; | |
14 | import java.util.Set; | |
15 | import java.util.stream.Collectors; | |
16 | ||
17 | import static java.util.stream.Collectors.joining; | |
18 | import static pro.verron.officestamper.utils.WmlFactory.*; | |
19 | ||
20 | /** | |
21 | * <p>CommentWrapper class.</p> | |
22 | * | |
23 | * @author Joseph Verron | |
24 | * @author Tom Hombergs | |
25 | * @version ${version} | |
26 | * @since 1.0.2 | |
27 | */ | |
28 | public class StandardComment | |
29 | implements Comment { | |
30 | private final Set<Comment> children = new HashSet<>(); | |
31 | private final WordprocessingMLPackage document; | |
32 | private Comments.Comment comment; | |
33 | private CommentRangeStart commentRangeStart; | |
34 | private CommentRangeEnd commentRangeEnd; | |
35 | private CommentReference commentReference; | |
36 | ||
37 | /** | |
38 | * Constructs a new StandardComment object. | |
39 | * | |
40 | * @param document the WordprocessingMLPackage document instance | |
41 | */ | |
42 | public StandardComment(WordprocessingMLPackage document) { | |
43 | this.document = document; | |
44 | } | |
45 | ||
46 | public static StandardComment create( | |
47 | WordprocessingMLPackage document, | |
48 | P parent, | |
49 | Placeholder placeholder, | |
50 | BigInteger id | |
51 | ) { | |
52 | var commentWrapper = new StandardComment(document); | |
53 |
1
1. create : removed call to pro/verron/officestamper/core/StandardComment::setComment → SURVIVED |
commentWrapper.setComment(newComment(id, placeholder.content())); |
54 |
1
1. create : removed call to pro/verron/officestamper/core/StandardComment::setCommentRangeStart → KILLED |
commentWrapper.setCommentRangeStart(newCommentRangeStart(id, parent)); |
55 |
1
1. create : removed call to pro/verron/officestamper/core/StandardComment::setCommentRangeEnd → KILLED |
commentWrapper.setCommentRangeEnd(newCommentRangeEnd(id, parent)); |
56 |
1
1. create : removed call to pro/verron/officestamper/core/StandardComment::setCommentReference → SURVIVED |
commentWrapper.setCommentReference(newCommentReference(id, parent)); |
57 |
1
1. create : replaced return value with null for pro/verron/officestamper/core/StandardComment::create → KILLED |
return commentWrapper; |
58 | } | |
59 | ||
60 | @Override public String toString() { | |
61 |
1
1. toString : replaced return value with "" for pro/verron/officestamper/core/StandardComment::toString → NO_COVERAGE |
return "StandardComment{comment={id=%s, content=%s, children=%s}}}".formatted(comment.getId(), |
62 | comment.getContent() | |
63 | .stream() | |
64 | .map(TextUtils::getText) | |
65 | .collect(Collectors.joining(",")), | |
66 | children.size()); | |
67 | } | |
68 | ||
69 | @Override public Placeholder asPlaceholder() { | |
70 | String string = this.getComment() | |
71 | .getContent() | |
72 | .stream() | |
73 | .filter(P.class::isInstance) | |
74 | .map(P.class::cast) | |
75 |
1
1. lambda$asPlaceholder$0 : replaced return value with null for pro/verron/officestamper/core/StandardComment::lambda$asPlaceholder$0 → KILLED |
.map(p -> StandardParagraph.from(new TextualDocxPart(document), p)) |
76 | .map(StandardParagraph::asString) | |
77 | .collect(joining()); | |
78 |
1
1. asPlaceholder : replaced return value with null for pro/verron/officestamper/core/StandardComment::asPlaceholder → KILLED |
return Placeholders.raw(string); |
79 | } | |
80 | ||
81 | /** | |
82 | * <p>getParent.</p> | |
83 | * | |
84 | * @return the comment's author. | |
85 | */ | |
86 | @Override public ContentAccessor getParent() { | |
87 |
1
1. getParent : replaced return value with null for pro/verron/officestamper/core/StandardComment::getParent → KILLED |
return DocumentUtil.findSmallestCommonParent(getCommentRangeStart(), getCommentRangeEnd()); |
88 | } | |
89 | ||
90 | /** | |
91 | * @return the elements in the document that are between the comment range anchors. | |
92 | */ | |
93 | @Override public List<Object> getElements() { | |
94 | List<Object> elements = new ArrayList<>(); | |
95 | boolean startFound = false; | |
96 | boolean endFound = false; | |
97 | var siblings = getParent().getContent(); | |
98 | for (Object element : siblings) { | |
99 |
2
1. getElements : negated conditional → KILLED 2. getElements : negated conditional → KILLED |
startFound = startFound || DocumentUtil.depthElementSearch(getCommentRangeStart(), element); |
100 |
2
1. getElements : negated conditional → KILLED 2. getElements : negated conditional → KILLED |
if (startFound && !endFound) elements.add(element); |
101 |
2
1. getElements : negated conditional → KILLED 2. getElements : negated conditional → KILLED |
endFound = endFound || DocumentUtil.depthElementSearch(getCommentRangeEnd(), element); |
102 | } | |
103 |
1
1. getElements : replaced return value with Collections.emptyList for pro/verron/officestamper/core/StandardComment::getElements → KILLED |
return elements; |
104 | } | |
105 | ||
106 | /** | |
107 | * <p>Getter for the field <code>commentRangeEnd</code>.</p> | |
108 | * | |
109 | * @return a {@link CommentRangeEnd} object | |
110 | */ | |
111 | @Override public CommentRangeEnd getCommentRangeEnd() { | |
112 |
1
1. getCommentRangeEnd : replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentRangeEnd → KILLED |
return commentRangeEnd; |
113 | } | |
114 | ||
115 | public void setCommentRangeEnd(CommentRangeEnd commentRangeEnd) { | |
116 | this.commentRangeEnd = commentRangeEnd; | |
117 | } | |
118 | ||
119 | /** | |
120 | * <p>Getter for the field <code>commentRangeStart</code>.</p> | |
121 | * | |
122 | * @return a {@link CommentRangeStart} object | |
123 | */ | |
124 | @Override public CommentRangeStart getCommentRangeStart() { | |
125 |
1
1. getCommentRangeStart : replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentRangeStart → KILLED |
return commentRangeStart; |
126 | } | |
127 | ||
128 | public void setCommentRangeStart(CommentRangeStart commentRangeStart) { | |
129 | this.commentRangeStart = commentRangeStart; | |
130 | } | |
131 | ||
132 | /** | |
133 | * <p>Getter for the field <code>commentReference</code>.</p> | |
134 | * | |
135 | * @return a {@link CommentReference} object | |
136 | */ | |
137 | @Override public CommentReference getCommentReference() { | |
138 |
1
1. getCommentReference : replaced return value with null for pro/verron/officestamper/core/StandardComment::getCommentReference → KILLED |
return commentReference; |
139 | } | |
140 | ||
141 | public void setCommentReference(CommentReference commentReference) { | |
142 | this.commentReference = commentReference; | |
143 | } | |
144 | ||
145 | /** | |
146 | * <p>Getter for the field <code>children</code>.</p> | |
147 | * | |
148 | * @return a {@link Set} object | |
149 | */ | |
150 | @Override public Set<Comment> getChildren() { | |
151 |
1
1. getChildren : replaced return value with Collections.emptySet for pro/verron/officestamper/core/StandardComment::getChildren → KILLED |
return children; |
152 | } | |
153 | ||
154 | public void setChildren(Set<Comment> children) { | |
155 | this.children.addAll(children); | |
156 | } | |
157 | ||
158 | /** | |
159 | * <p>Getter for the field <code>comment</code>.</p> | |
160 | * | |
161 | * @return a {@link Comments.Comment} object | |
162 | */ | |
163 | @Override public Comments.Comment getComment() { | |
164 |
1
1. getComment : replaced return value with null for pro/verron/officestamper/core/StandardComment::getComment → KILLED |
return comment; |
165 | } | |
166 | ||
167 | public void setComment(Comments.Comment comment) { | |
168 | this.comment = comment; | |
169 | } | |
170 | ||
171 | @Override public WordprocessingMLPackage getDocument() { | |
172 |
1
1. getDocument : replaced return value with null for pro/verron/officestamper/core/StandardComment::getDocument → KILLED |
return document; |
173 | } | |
174 | ||
175 | } | |
Mutations | ||
53 |
1.1 |
|
54 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 |
|
61 |
1.1 |
|
75 |
1.1 |
|
78 |
1.1 |
|
87 |
1.1 |
|
99 |
1.1 2.2 |
|
100 |
1.1 2.2 |
|
101 |
1.1 2.2 |
|
103 |
1.1 |
|
112 |
1.1 |
|
125 |
1.1 |
|
138 |
1.1 |
|
151 |
1.1 |
|
164 |
1.1 |
|
172 |
1.1 |