1 | package fr.sii.ogham.core.condition; | |
2 | ||
3 | import java.util.regex.Pattern; | |
4 | ||
5 | import fr.sii.ogham.core.env.PropertyResolver; | |
6 | import fr.sii.ogham.core.util.EqualsBuilder; | |
7 | import fr.sii.ogham.core.util.HashCodeBuilder; | |
8 | ||
9 | /** | |
10 | * Condition that checks if the provided property value matches the provided | |
11 | * pattern. | |
12 | * | |
13 | * @author Aurélien Baudet | |
14 | * | |
15 | * @param <T> | |
16 | * The type of the object to test for acceptance. Has no effect on | |
17 | * the acceptance | |
18 | */ | |
19 | public class PropertyPatternCondition<T> implements Condition<T> { | |
20 | /** | |
21 | * The properties to use for checking if property is defined or not | |
22 | */ | |
23 | private PropertyResolver propertyResolver; | |
24 | ||
25 | /** | |
26 | * The key to check if defined in the properties | |
27 | */ | |
28 | private String key; | |
29 | ||
30 | /** | |
31 | * The pattern to match | |
32 | */ | |
33 | private Pattern pattern; | |
34 | ||
35 | /** | |
36 | * Initialize the condition with the provided key. It will check the | |
37 | * existence of this key into the provided properties. | |
38 | * | |
39 | * @param key | |
40 | * The key of the property | |
41 | * @param pattern | |
42 | * The pattern to match | |
43 | * @param propertyResolver | |
44 | * the property resolver used to get properties values | |
45 | */ | |
46 | public PropertyPatternCondition(String key, Pattern pattern, PropertyResolver propertyResolver) { | |
47 | super(); | |
48 | this.key = key; | |
49 | this.pattern = pattern; | |
50 | this.propertyResolver = propertyResolver; | |
51 | } | |
52 | ||
53 | @Override | |
54 | public boolean accept(T obj) { | |
55 | String value = propertyResolver.getProperty(key); | |
56 |
8
1. accept : replaced boolean return with true for fr/sii/ogham/core/condition/PropertyPatternCondition::accept → NO_COVERAGE 2. accept : negated conditional → NO_COVERAGE 3. accept : negated conditional → NO_COVERAGE 4. accept : negated conditional → NO_COVERAGE 5. accept : replaced boolean return with true for fr/sii/ogham/core/condition/PropertyPatternCondition::accept → KILLED 6. accept : negated conditional → KILLED 7. accept : negated conditional → KILLED 8. accept : negated conditional → KILLED |
return value!=null && pattern!=null && pattern.matcher(value).matches(); |
57 | } | |
58 | ||
59 | @Override | |
60 | public boolean equals(Object obj) { | |
61 |
2
1. equals : replaced boolean return with false for fr/sii/ogham/core/condition/PropertyPatternCondition::equals → NO_COVERAGE 2. equals : replaced boolean return with true for fr/sii/ogham/core/condition/PropertyPatternCondition::equals → NO_COVERAGE |
return new EqualsBuilder(this, obj).appendFields("key", "pattern", "propertyResolver").isEqual(); |
62 | } | |
63 | ||
64 | @Override | |
65 | public int hashCode() { | |
66 |
1
1. hashCode : replaced int return with 0 for fr/sii/ogham/core/condition/PropertyPatternCondition::hashCode → NO_COVERAGE |
return new HashCodeBuilder().append(key, pattern, propertyResolver).hashCode(); |
67 | } | |
68 | ||
69 | @Override | |
70 | public String toString() { | |
71 | StringBuilder builder = new StringBuilder(); | |
72 | builder.append("(").append(key).append(" matches ").append(pattern).append(" in properties ?)"); | |
73 |
1
1. toString : replaced return value with "" for fr/sii/ogham/core/condition/PropertyPatternCondition::toString → NO_COVERAGE |
return builder.toString(); |
74 | } | |
75 | } | |
Mutations | ||
56 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
61 |
1.1 2.2 |
|
66 |
1.1 |
|
73 |
1.1 |