1 | package fr.sii.ogham.core.condition.fluent; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Collections; | |
5 | import java.util.List; | |
6 | ||
7 | import fr.sii.ogham.core.condition.Condition; | |
8 | ||
9 | /** | |
10 | * Implementation that helps writing conditions in a fluent way. | |
11 | * | |
12 | * For example: | |
13 | * | |
14 | * <pre> | |
15 | * requiredClass("javax.mail.Transport").and(requiredClass("foo.Bar")); | |
16 | * </pre> | |
17 | * | |
18 | * <p> | |
19 | * It wraps a real condition in order to provide two new methods: | |
20 | * <ul> | |
21 | * <li><code>and</code>: to make a AND operator between current condition and | |
22 | * the condiions provided in parameter</li> | |
23 | * <li><code>or</code>: to make a OR operator between current condition and the | |
24 | * condiions provided in parameter</li> | |
25 | * </ul> | |
26 | * | |
27 | * @author Aurélien Baudet | |
28 | * | |
29 | * @param <T> | |
30 | * the type of the object that is under conditions | |
31 | */ | |
32 | public class FluentCondition<T> implements Condition<T> { | |
33 | /** | |
34 | * The original condition | |
35 | */ | |
36 | private final Condition<T> delegate; | |
37 | ||
38 | /** | |
39 | * Wraps the real condition in order to provide a fluent API. Calling | |
40 | * {@link #accept(Object)} will be delegated to the underlying condition. | |
41 | * | |
42 | * @param delegate | |
43 | * the wrapped condition | |
44 | */ | |
45 | public FluentCondition(Condition<T> delegate) { | |
46 | super(); | |
47 | this.delegate = delegate; | |
48 | } | |
49 | ||
50 | /** | |
51 | * Create a logical AND operator between current condition and conditions | |
52 | * provided in parameters. | |
53 | * | |
54 | * For example: | |
55 | * | |
56 | * <pre> | |
57 | * requiredClass("javax.mail.Transport").and(requiredClass("foo.Bar")); | |
58 | * </pre> | |
59 | * | |
60 | * Means that the result will be true only if the result of the current | |
61 | * condition (<code>requiredClass("javax.mail.Transport")</code>) is true | |
62 | * and the result provided condition (<code>requireClass("foo.Bar")</code>) | |
63 | * is true. | |
64 | * | |
65 | * <p> | |
66 | * If one of the condition result is false, then other conditions are not | |
67 | * evaluated. | |
68 | * </p> | |
69 | * | |
70 | * @param conditions | |
71 | * one or several conditions | |
72 | * @return the fluent condition | |
73 | */ | |
74 | @SafeVarargs | |
75 | public final FluentCondition<T> and(Condition<T>... conditions) { | |
76 | List<Condition<T>> merged = new ArrayList<>(); | |
77 | merged.add(delegate); | |
78 | Collections.addAll(merged, conditions); | |
79 |
2
1. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/FluentCondition::and → NO_COVERAGE 2. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/FluentCondition::and → KILLED |
return Conditions.and(merged); |
80 | } | |
81 | ||
82 | /** | |
83 | * Create a logical OR operator between current condition and conditions | |
84 | * provided in parameters. | |
85 | * | |
86 | * For example: | |
87 | * | |
88 | * <pre> | |
89 | * requiredClass("javax.mail.Transport").or(requiredClass("foo.Bar")); | |
90 | * </pre> | |
91 | * | |
92 | * Means that the result will be true if either the result of the current | |
93 | * condition (<code>requiredClass("javax.mail.Transport")</code>) is true or | |
94 | * the result provided condition (<code>requireClass("foo.Bar")</code>) is | |
95 | * true. | |
96 | * | |
97 | * <p> | |
98 | * If one of the condition result is true, then other conditions are not | |
99 | * evaluated. | |
100 | * </p> | |
101 | * | |
102 | * @param conditions | |
103 | * one or several conditions | |
104 | * @return the fluent condition | |
105 | */ | |
106 | @SafeVarargs | |
107 | public final FluentCondition<T> or(Condition<T>... conditions) { | |
108 | List<Condition<T>> merged = new ArrayList<>(); | |
109 | merged.add(delegate); | |
110 | Collections.addAll(merged, conditions); | |
111 |
6
1. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/FluentCondition::or → NO_COVERAGE 2. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/FluentCondition::or → TIMED_OUT 3. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/FluentCondition::or → KILLED 4. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/FluentCondition::or → KILLED 5. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/FluentCondition::or → KILLED 6. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/FluentCondition::or → KILLED |
return Conditions.or(merged); |
112 | } | |
113 | ||
114 | @Override | |
115 | public boolean accept(T obj) { | |
116 |
12
1. accept : replaced boolean return with false for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → NO_COVERAGE 2. accept : replaced boolean return with true for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → SURVIVED 3. accept : replaced boolean return with true for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → NO_COVERAGE 4. accept : replaced boolean return with false for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → TIMED_OUT 5. accept : replaced boolean return with true for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → TIMED_OUT 6. accept : replaced boolean return with false for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → KILLED 7. accept : replaced boolean return with false for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → KILLED 8. accept : replaced boolean return with false for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → KILLED 9. accept : replaced boolean return with false for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → KILLED 10. accept : replaced boolean return with true for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → KILLED 11. accept : replaced boolean return with true for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → KILLED 12. accept : replaced boolean return with true for fr/sii/ogham/core/condition/fluent/FluentCondition::accept → KILLED |
return delegate.accept(obj); |
117 | } | |
118 | ||
119 | @Override | |
120 | public String toString() { | |
121 |
1
1. toString : replaced return value with "" for fr/sii/ogham/core/condition/fluent/FluentCondition::toString → NO_COVERAGE |
return delegate.toString(); |
122 | } | |
123 | | |
124 | } | |
Mutations | ||
79 |
1.1 2.2 |
|
111 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
116 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 |
|
121 |
1.1 |