CommentProcessorFactory.java

1
package pro.verron.officestamper.preset;
2
3
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
4
import org.springframework.lang.Nullable;
5
import pro.verron.officestamper.api.CommentProcessor;
6
import pro.verron.officestamper.api.OfficeStamper;
7
import pro.verron.officestamper.api.OfficeStamperConfiguration;
8
import pro.verron.officestamper.api.ParagraphPlaceholderReplacer;
9
import pro.verron.officestamper.core.DocxStamper;
10
import pro.verron.officestamper.preset.processors.displayif.DisplayIfProcessor;
11
import pro.verron.officestamper.preset.processors.repeat.RepeatProcessor;
12
import pro.verron.officestamper.preset.processors.repeatdocpart.RepeatDocPartProcessor;
13
import pro.verron.officestamper.preset.processors.repeatparagraph.ParagraphRepeatProcessor;
14
import pro.verron.officestamper.preset.processors.replacewith.ReplaceWithProcessor;
15
import pro.verron.officestamper.preset.processors.table.TableResolver;
16
17
/// Factory class to create the correct comment processor for a given comment.
18
///
19
/// @author Joseph Verron
20
/// @version ${version}
21
/// @since 1.6.4
22
public class CommentProcessorFactory {
23
    private final OfficeStamperConfiguration configuration;
24
25
    /// Creates a new CommentProcessorFactory.
26
    ///
27
    /// @param configuration the configuration to use for the created processors.
28
    public CommentProcessorFactory(OfficeStamperConfiguration configuration) {
29
        this.configuration = configuration;
30
    }
31
32
    /// Creates new repeatParagraph [CommentProcessor] with default configuration.
33
    ///
34
    /// @param pr a [ParagraphPlaceholderReplacer] object
35
    ///
36
    /// @return a [CommentProcessor] object
37
    public CommentProcessor repeatParagraph(ParagraphPlaceholderReplacer pr) {
38 1 1. repeatParagraph : replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::repeatParagraph → KILLED
        return ParagraphRepeatProcessor.newInstance(pr);
39
    }
40
41
    /// Creates new repeatDocPart [CommentProcessor] with default configuration.
42
    ///
43
    /// @param pr a [ParagraphPlaceholderReplacer] object
44
    ///
45
    /// @return a [CommentProcessor] object
46
    public CommentProcessor repeatDocPart(ParagraphPlaceholderReplacer pr) {
47 1 1. repeatDocPart : replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::repeatDocPart → KILLED
        return RepeatDocPartProcessor.newInstance(pr, getStamper());
48
    }
49
50
    private OfficeStamper<WordprocessingMLPackage> getStamper() {
51 2 1. lambda$getStamper$0 : removed call to pro/verron/officestamper/core/DocxStamper::stamp → TIMED_OUT
2. getStamper : replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::getStamper → KILLED
        return (template, context, output) -> new DocxStamper(configuration).stamp(template, context, output);
52
    }
53
54
    /// Creates new repeating [CommentProcessor] with default configuration.
55
    ///
56
    /// @param pr a [ParagraphPlaceholderReplacer] object
57
    ///
58
    /// @return a [CommentProcessor] object
59
    public CommentProcessor repeat(ParagraphPlaceholderReplacer pr) {
60 1 1. repeat : replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::repeat → KILLED
        return RepeatProcessor.newInstance(pr);
61
    }
62
63
    /// Creates new tableResolver [CommentProcessor] with default configuration.
64
    ///
65
    /// @param pr a [ParagraphPlaceholderReplacer] object
66
    ///
67
    /// @return a [CommentProcessor] object
68
    public CommentProcessor tableResolver(ParagraphPlaceholderReplacer pr) {
69 1 1. tableResolver : replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::tableResolver → KILLED
        return TableResolver.newInstance(pr);
70
    }
71
72
    /// Creates new displayIf [CommentProcessor] with default configuration.
73
    ///
74
    /// @param pr a [ParagraphPlaceholderReplacer] object
75
    ///
76
    /// @return a [CommentProcessor] object
77
    public CommentProcessor displayIf(ParagraphPlaceholderReplacer pr) {
78 1 1. displayIf : replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::displayIf → KILLED
        return DisplayIfProcessor.newInstance(pr);
79
    }
80
81
    /// Creates new replaceWith [CommentProcessor] with default configuration.
82
    ///
83
    /// @param pr a [ParagraphPlaceholderReplacer] object
84
    ///
85
    /// @return a [CommentProcessor] object
86
    public CommentProcessor replaceWith(ParagraphPlaceholderReplacer pr) {
87 1 1. replaceWith : replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::replaceWith → KILLED
        return ReplaceWithProcessor.newInstance(pr);
88
    }
89
90
    /// Used to resolve a table in the template document.
91
    /// Take the table passed-in to fill an existing Tbl object in the document.
92
    ///
93
    /// @author Joseph Verron
94
    /// @version ${version}
95
    /// @since 1.6.2
96
    public interface ITableResolver {
97
        /// Resolves the given table by manipulating the given table in the template.
98
        ///
99
        /// @param table the table to resolve.
100
        void resolveTable(@Nullable StampTable table);
101
    }
102
103
    /// Interface for processors that replace a single word with an expression defined
104
    /// in a comment.
105
    ///
106
    /// @author Joseph Verron
107
    /// @author Tom Hombergs
108
    /// @version ${version}
109
    /// @since 1.0.8
110
    public interface IReplaceWithProcessor {
111
112
        /// Replace a single word inside a paragraph with an expression defined in the comment.
113
        /// The comment should apply to a single word for the replacement to take effect.
114
        ///
115
        /// @param expression the expression to replace the text with
116
        void replaceWordWith(@Nullable String expression);
117
    }
118
119
    /// An interface that defines a processor for repeating a paragraph
120
    /// for each element present in the given iterable collection of objects.
121
    ///
122
    /// @author Joseph Verron
123
    /// @author Romain Lamarche
124
    /// @version ${version}
125
    /// @since 1.0.0
126
    public interface IParagraphRepeatProcessor {
127
        /// Mark a paragraph to be copied once for each element in the passed-in iterable.
128
        /// Within each copy, placeholder evaluation context is the next object in the iterable.
129
        ///
130
        /// @param objects objects serving as evaluation context seeding a new copy.
131
        void repeatParagraph(@Nullable Iterable<Object> objects);
132
    }
133
134
    /// An interface that defines a processor for repeating a document part
135
    /// for each element present in the given iterable collection of objects.
136
    ///
137
    /// @author Joseph Verron
138
    /// @author Artem Medvedev
139
    /// @version ${version}
140
    /// @since 1.0.0
141
    public interface IRepeatDocPartProcessor {
142
        /// Mark a document part to be copied once for each element in the passed-in iterable.
143
        /// Within each copy, placeholder evaluation context is the next object in the iterable.
144
        ///
145
        /// @param objects objects serving as evaluation context seeding a new copy.
146
        void repeatDocPart(@Nullable Iterable<Object> objects);
147
    }
148
149
    /// An interface that defines a processor for repeating a table row
150
    /// for each element present in the given iterable collection of objects.
151
    ///
152
    /// @author Joseph Verron
153
    /// @author Tom Hombergs
154
    /// @version ${version}
155
    /// @since 1.0.0
156
    public interface IRepeatProcessor {
157
        /// Mark a table row to be copied once for each element in the passed-in iterable.
158
        /// Within each copy, placeholder evaluation context is the next object in the iterable.
159
        ///
160
        /// @param objects objects serving as evaluation context seeding a new copy.
161
        void repeatTableRow(@Nullable Iterable<Object> objects);
162
    }
163
164
    /// Interface for processors used to delete paragraphs or tables from the document, depending on condition.
165
    ///
166
    /// @author Joseph Verron
167
    /// @author Tom Hombergs
168
    /// @version ${version}
169
    /// @since 1.0.0
170
    public interface IDisplayIfProcessor {
171
172
        /// @param condition if true, keep the paragraph surrounding the comment, else remove.
173
        void displayParagraphIf(@Nullable Boolean condition);
174
175
        /// @param condition if non-null, keep the paragraph surrounding the comment, else remove.
176
        void displayParagraphIfPresent(@Nullable Object condition);
177
178
        /// @param condition if true, keep the table row surrounding the comment, else remove.
179
        void displayTableRowIf(@Nullable Boolean condition);
180
181
        /// @param condition if non-null, keep the table row surrounding the comment, else remove.
182
        void displayTableRowIfPresent(@Nullable Object condition);
183
184
        /// @param condition if true, keep the table surrounding the comment, else remove.
185
        void displayTableIf(@Nullable Boolean condition);
186
187
        /// @param condition if non-null, keep the table surrounding the comment, else remove.
188
        void displayTableIfPresent(@Nullable Object condition);
189
190
        /// @param condition if true, keep the selected words surrounding the comment, else remove.
191
        void displayWordsIf(@Nullable Boolean condition);
192
193
        /// @param condition if non-null, keep the selected words surrounding the comment, else remove.
194
        void displayWordsIfPresent(@Nullable Object condition);
195
196
        /// @param condition if true, keep the selected elements surrounding the comment, else remove.
197
        void displayDocPartIf(@Nullable Boolean condition);
198
199
        /// @param condition if non-null, keep the selected elements surrounding the comment, else remove.
200
        void displayDocPartIfPresent(@Nullable Object condition);
201
    }
202
}

Mutations

38

1.1
Location : repeatParagraph
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#34]
replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::repeatParagraph → KILLED

47

1.1
Location : repeatDocPart
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#34]
replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::repeatDocPart → KILLED

51

1.1
Location : lambda$getStamper$0
Killed by : none
removed call to pro/verron/officestamper/core/DocxStamper::stamp → TIMED_OUT

2.2
Location : getStamper
Killed by : pro.verron.officestamper.test.RepeatDocPartBadPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RepeatDocPartBadPlaceholderTest]/[method:testBadExpressionShouldNotBlockCallerThread()]
replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::getStamper → KILLED

60

1.1
Location : repeat
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#34]
replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::repeat → KILLED

69

1.1
Location : tableResolver
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#34]
replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::tableResolver → KILLED

78

1.1
Location : displayIf
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#34]
replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::displayIf → KILLED

87

1.1
Location : replaceWith
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#34]
replaced return value with null for pro/verron/officestamper/preset/CommentProcessorFactory::replaceWith → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1