1 | package fr.sii.ogham.core.condition.fluent; | |
2 | ||
3 | import java.util.List; | |
4 | import java.util.regex.Pattern; | |
5 | ||
6 | import fr.sii.ogham.core.condition.Condition; | |
7 | import fr.sii.ogham.core.env.PropertyResolver; | |
8 | import fr.sii.ogham.core.message.Message; | |
9 | ||
10 | /** | |
11 | * Helper to write fluent conditions like: | |
12 | * | |
13 | * <pre> | |
14 | * requiredClass("javax.mail.Transport").and(not(requiredClass("foo.Bar"))); | |
15 | * </pre> | |
16 | * | |
17 | * To do this, you need to add the following static import: | |
18 | * | |
19 | * <pre> | |
20 | * import static fr.sii.ogham.core.builder.condition.MessageConditions.*; | |
21 | * </pre> | |
22 | * | |
23 | * <p> | |
24 | * This implementation is specialized for {@link Message}s that may be needed if | |
25 | * you are using Java 7 (because generic chaining resolution doesn't work well | |
26 | * with Java 7). | |
27 | * | |
28 | * @author Aurélien Baudet | |
29 | * | |
30 | */ | |
31 | public final class MessageConditions { | |
32 | /** | |
33 | * Parenthesis operator to handle priorities: | |
34 | * | |
35 | * <pre> | |
36 | * $(requiredProperty(propertyResolver, "mail.host").or(requiredProperty(propertyResolver, "mail.smtp.host"))) | |
37 | * .and(requiredProperty(propertyResolver, "mail.port").or(requiredProperty(propertyResolver, "mail.smtp.port"))) | |
38 | * </pre> | |
39 | * | |
40 | * Meaning "(mail.host is defined OR mail.smtp.host is defined) AND | |
41 | * (mail.port is defined OR mail.smtp.port is defined)". | |
42 | * | |
43 | * <p> | |
44 | * Without this operator, you had to write this: | |
45 | * | |
46 | * <pre> | |
47 | * requiredProperty(propertyResolver, "mail.host").or(requiredProperty(propertyResolver, "mail.smtp.host")) | |
48 | * .and(requiredProperty(propertyResolver, "mail.port").or(requiredProperty(propertyResolver, "mail.smtp.port")) | |
49 | * </pre> | |
50 | * | |
51 | * Meaning "mail.host is defined OR mail.smtp.host is defined AND (mail.port | |
52 | * is defined OR mail.smtp.port is defined)". | |
53 | * | |
54 | * So the behavior won't be the same. | |
55 | * | |
56 | * @param condition | |
57 | * the condition to surround | |
58 | * @return the fluent condition | |
59 | */ | |
60 | @SuppressWarnings("squid:S00100") | |
61 | public static FluentCondition<Message> $(Condition<Message> condition) { | |
62 |
2
1. $ : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::$ → NO_COVERAGE 2. $ : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::$ → KILLED |
return Conditions.$(condition); |
63 | } | |
64 | ||
65 | /** | |
66 | * And operator between the provided conditions: | |
67 | * | |
68 | * <pre> | |
69 | * and(requiredClass("javax.mail.Transport"), requiredClass("foo.Bar")); | |
70 | * </pre> | |
71 | * | |
72 | * Means that the result will be true only if | |
73 | * <code>javax.mail.Transport</code> and <code>foo.Bar</code> classes are | |
74 | * present in the classpath. | |
75 | * | |
76 | * <p> | |
77 | * If one of the condition result is false, then other conditions are not | |
78 | * evaluated. | |
79 | * </p> | |
80 | * | |
81 | * @param conditions | |
82 | * one or several conditions | |
83 | * @return the fluent condition | |
84 | */ | |
85 | @SafeVarargs | |
86 | public static FluentCondition<Message> and(Condition<Message>... conditions) { | |
87 |
2
1. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::and → NO_COVERAGE 2. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::and → KILLED |
return Conditions.and(conditions); |
88 | } | |
89 | ||
90 | /** | |
91 | * And operator between the provided conditions. It is a helper method that | |
92 | * is useful when you need to construct conditions separately: | |
93 | * | |
94 | * <pre> | |
95 | * List<Condition<Message>> conditions = new ArrayList<>(); | |
96 | * conditions.add(requiredClass("javax.mail.Transport")); | |
97 | * conditions.add(requiredClass("foo.Bar")); | |
98 | * | |
99 | * and(conditions); | |
100 | * </pre> | |
101 | * | |
102 | * Means that the result will be true only if | |
103 | * <code>javax.mail.Transport</code> and <code>foo.Bar</code> classes are | |
104 | * present in the classpath. | |
105 | * | |
106 | * <p> | |
107 | * If one of the condition result is false, then other conditions are not | |
108 | * evaluated. | |
109 | * </p> | |
110 | * | |
111 | * @param conditions | |
112 | * one or several conditions | |
113 | * @return the fluent condition | |
114 | */ | |
115 | public static FluentCondition<Message> and(List<Condition<Message>> conditions) { | |
116 |
2
1. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::and → NO_COVERAGE 2. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::and → KILLED |
return Conditions.and(conditions); |
117 | } | |
118 | ||
119 | /** | |
120 | * Or operator between the provided conditions: | |
121 | * | |
122 | * <pre> | |
123 | * or(requiredClass("javax.mail.Transport"), requiredClass("foo.Bar")); | |
124 | * </pre> | |
125 | * | |
126 | * Means that the result will be true if either | |
127 | * <code>javax.mail.Transport</code> or <code>foo.Bar</code> class is | |
128 | * present in the classpath. | |
129 | * | |
130 | * <p> | |
131 | * If one of the condition result is true, then other conditions are not | |
132 | * evaluated. | |
133 | * </p> | |
134 | * | |
135 | * @param conditions | |
136 | * one or several conditions | |
137 | * @return the fluent condition | |
138 | */ | |
139 | @SafeVarargs | |
140 | public static FluentCondition<Message> or(Condition<Message>... conditions) { | |
141 |
2
1. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::or → NO_COVERAGE 2. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::or → KILLED |
return Conditions.or(conditions); |
142 | } | |
143 | ||
144 | /** | |
145 | * Or operator between the provided conditions. It is a helper method that | |
146 | * is useful when you need to construct conditions separately: | |
147 | * | |
148 | * <pre> | |
149 | * List<Condition<Message>> conditions = new ArrayList<>(); | |
150 | * conditions.add(requiredClass("javax.mail.Transport")); | |
151 | * conditions.add(requiredClass("foo.Bar")); | |
152 | * | |
153 | * or(conditions); | |
154 | * </pre> | |
155 | * | |
156 | * Means that the result will be true if either | |
157 | * <code>javax.mail.Transport</code> or <code>foo.Bar</code> class is | |
158 | * present in the classpath. | |
159 | * | |
160 | * @param conditions | |
161 | * one or several conditions | |
162 | * @return the fluent condition | |
163 | */ | |
164 | public static FluentCondition<Message> or(List<Condition<Message>> conditions) { | |
165 |
2
1. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::or → NO_COVERAGE 2. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::or → KILLED |
return Conditions.or(conditions); |
166 | } | |
167 | ||
168 | /** | |
169 | * Not operator to reverse provided condition: | |
170 | * | |
171 | * <pre> | |
172 | * not(requiredClass("javax.mail.Transport)); | |
173 | * </pre> | |
174 | * | |
175 | * Means that the result will be true if the class | |
176 | * <code>javax.mail.Transport</code> is not present in the classpath. | |
177 | * | |
178 | * <p> | |
179 | * If one of the condition result is true, then other conditions are not | |
180 | * evaluated. | |
181 | * </p> | |
182 | * | |
183 | * @param condition | |
184 | * the condition to reverse | |
185 | * @return the fluent condition | |
186 | */ | |
187 | public static FluentCondition<Message> not(Condition<Message> condition) { | |
188 |
2
1. not : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::not → NO_COVERAGE 2. not : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::not → KILLED |
return Conditions.not(condition); |
189 | } | |
190 | ||
191 | /** | |
192 | * Check if a property is present in the configuration properties. The | |
193 | * configuration properties are available through the property resolver. | |
194 | * | |
195 | * <pre> | |
196 | * requiredProperty(propertyResolver, "mail.host"); | |
197 | * </pre> | |
198 | * | |
199 | * Means that the result will be true only if the property | |
200 | * <code>mail.host</code> is present in the property resolver. | |
201 | * | |
202 | * @param propertyResolver | |
203 | * the resolver that is used to access property values | |
204 | * @param property | |
205 | * the property name | |
206 | * @return the fluent condition | |
207 | */ | |
208 | public static FluentCondition<Message> requiredProperty(PropertyResolver propertyResolver, String property) { | |
209 |
6
1. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredProperty → NO_COVERAGE 2. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredProperty → KILLED 3. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredProperty → KILLED 4. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredProperty → KILLED 5. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredProperty → KILLED 6. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredProperty → KILLED |
return Conditions.requiredProperty(propertyResolver, property); |
210 | } | |
211 | ||
212 | /** | |
213 | * Check if a property has a particular value in the configuration | |
214 | * properties. The configuration properties are available through the | |
215 | * property resolver. | |
216 | * | |
217 | * <pre> | |
218 | * requiredPropertyValue(propertyResolver, "mail.host", "localhost"); | |
219 | * </pre> | |
220 | * | |
221 | * Means that the result will be true only if the property | |
222 | * <code>mail.host</code> is present in the property resolver and its value | |
223 | * is exactly <code>localhost</code>. | |
224 | * | |
225 | * @param propertyResolver | |
226 | * the resolver that is used to access property values | |
227 | * @param property | |
228 | * the property name | |
229 | * @param value | |
230 | * the exact value to match | |
231 | * @return the fluent condition | |
232 | */ | |
233 | public static FluentCondition<Message> requiredPropertyValue(PropertyResolver propertyResolver, String property, String value) { | |
234 |
2
1. requiredPropertyValue : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredPropertyValue → NO_COVERAGE 2. requiredPropertyValue : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredPropertyValue → KILLED |
return Conditions.requiredPropertyValue(propertyResolver, property, value); |
235 | } | |
236 | ||
237 | /** | |
238 | * Check if a property value matches the pattern in the configuration | |
239 | * properties. The configuration properties are available through the | |
240 | * property resolver. | |
241 | * | |
242 | * <pre> | |
243 | * requiredPropertyValue(propertyResolver, "mail.host", Pattern.compile("local.*")); | |
244 | * </pre> | |
245 | * | |
246 | * Means that the result will be true only if the property | |
247 | * <code>mail.host</code> is present in the property resolver and its value | |
248 | * matches the pattern <code>local.*</code>. | |
249 | * | |
250 | * @param propertyResolver | |
251 | * the resolver that is used to access property values | |
252 | * @param property | |
253 | * the property name | |
254 | * @param pattern | |
255 | * the pattern used to check if the value matches | |
256 | * @return the fluent condition | |
257 | */ | |
258 | public static FluentCondition<Message> requiredPropertyValue(PropertyResolver propertyResolver, String property, Pattern pattern) { | |
259 |
2
1. requiredPropertyValue : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredPropertyValue → NO_COVERAGE 2. requiredPropertyValue : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredPropertyValue → KILLED |
return Conditions.requiredPropertyValue(propertyResolver, property, pattern); |
260 | } | |
261 | ||
262 | /** | |
263 | * Check if a class is present in the classpath. | |
264 | * | |
265 | * <pre> | |
266 | * requiredClass("javax.mail.Transport"); | |
267 | * </pre> | |
268 | * | |
269 | * Means that the result will be true only if the class | |
270 | * <code>javax.mail.Transport</code> is present in the classpath. | |
271 | * | |
272 | * @param className | |
273 | * the class to check | |
274 | * @return the fluent condition | |
275 | */ | |
276 | public static FluentCondition<Message> requiredClass(String className) { | |
277 |
1
1. requiredClass : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::requiredClass → NO_COVERAGE |
return Conditions.requiredClass(className); |
278 | } | |
279 | ||
280 | /** | |
281 | * A condition that always returns true. | |
282 | * | |
283 | * @return the fluent condition | |
284 | */ | |
285 | public static FluentCondition<Message> alwaysTrue() { | |
286 |
2
1. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::alwaysTrue → NO_COVERAGE 2. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::alwaysTrue → KILLED |
return Conditions.alwaysTrue(); |
287 | } | |
288 | ||
289 | /** | |
290 | * A condition that always returns false. | |
291 | * | |
292 | * @return the fluent condition | |
293 | */ | |
294 | public static FluentCondition<Message> alwaysFalse() { | |
295 |
2
1. alwaysFalse : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::alwaysFalse → NO_COVERAGE 2. alwaysFalse : replaced return value with null for fr/sii/ogham/core/condition/fluent/MessageConditions::alwaysFalse → KILLED |
return Conditions.alwaysFalse(); |
296 | } | |
297 | ||
298 | private MessageConditions() { | |
299 | super(); | |
300 | } | |
301 | } | |
Mutations | ||
62 |
1.1 2.2 |
|
87 |
1.1 2.2 |
|
116 |
1.1 2.2 |
|
141 |
1.1 2.2 |
|
165 |
1.1 2.2 |
|
188 |
1.1 2.2 |
|
209 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
234 |
1.1 2.2 |
|
259 |
1.1 2.2 |
|
277 |
1.1 |
|
286 |
1.1 2.2 |
|
295 |
1.1 2.2 |