| 1 | package fr.sii.ogham.core.env; | |
| 2 | ||
| 3 | import java.util.Arrays; | |
| 4 | import java.util.List; | |
| 5 | ||
| 6 | /** | |
| 7 | * Resolve properties by requesting delegates. | |
| 8 | * | |
| 9 | * The first registered delegate is requested for a property value or existence. | |
| 10 | * If the first resolver can provide the property (property exists), then the | |
| 11 | * property value is returned. If the first can't provide the property, then the | |
| 12 | * second is requested and so on until one resolver can provide the value. | |
| 13 | * | |
| 14 | * @author Aurélien Baudet | |
| 15 | * | |
| 16 | */ | |
| 17 | public class FirstExistingPropertiesResolver implements PropertyResolver { | |
| 18 | private final List<PropertyResolver> delegates; | |
| 19 | ||
| 20 | /** | |
| 21 | * Initialize the resolver with a list of sub-resolvers that will be | |
| 22 | * executed in order to search for a property value. | |
| 23 | * | |
| 24 | * @param delegates | |
| 25 | * the ordered list of resolvers | |
| 26 | */ | |
| 27 | public FirstExistingPropertiesResolver(PropertyResolver... delegates) { | |
| 28 | this(Arrays.asList(delegates)); | |
| 29 | } | |
| 30 | ||
| 31 | /** | |
| 32 | * Initialize the resolver with a list of sub-resolvers that will be | |
| 33 | * executed in order to search for a property value. | |
| 34 | * | |
| 35 | * @param delegates | |
| 36 | * the ordered list of resolvers | |
| 37 | */ | |
| 38 | public FirstExistingPropertiesResolver(List<PropertyResolver> delegates) { | |
| 39 | super(); | |
| 40 | this.delegates = delegates; | |
| 41 | } | |
| 42 | ||
| 43 | @Override | |
| 44 | public boolean containsProperty(String key) { | |
| 45 | for (PropertyResolver resolver : delegates) { | |
| 46 |
4
1. containsProperty : negated conditional → NO_COVERAGE 2. containsProperty : negated conditional → SURVIVED 3. containsProperty : negated conditional → KILLED 4. containsProperty : negated conditional → KILLED |
if (resolver.containsProperty(key)) { |
| 47 |
3
1. containsProperty : replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → NO_COVERAGE 2. containsProperty : replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED 3. containsProperty : replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED |
return true; |
| 48 | } | |
| 49 | } | |
| 50 |
4
1. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → NO_COVERAGE 2. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED 3. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED 4. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → KILLED |
return false; |
| 51 | } | |
| 52 | ||
| 53 | @Override | |
| 54 | public String getProperty(String key) { | |
| 55 | for (PropertyResolver resolver : delegates) { | |
| 56 |
4
1. getProperty : negated conditional → SURVIVED 2. getProperty : negated conditional → NO_COVERAGE 3. getProperty : negated conditional → TIMED_OUT 4. getProperty : negated conditional → KILLED |
if (resolver.containsProperty(key)) { |
| 57 |
4
1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE 2. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → SURVIVED 3. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT 4. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED |
return resolver.getProperty(key); |
| 58 | } | |
| 59 | } | |
| 60 |
5
1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE 2. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT 3. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 4. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 5. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED |
return null; |
| 61 | } | |
| 62 | ||
| 63 | @Override | |
| 64 | public String getProperty(String key, String defaultValue) { | |
| 65 | for (PropertyResolver resolver : delegates) { | |
| 66 |
4
1. getProperty : negated conditional → SURVIVED 2. getProperty : negated conditional → NO_COVERAGE 3. getProperty : negated conditional → TIMED_OUT 4. getProperty : negated conditional → KILLED |
if (resolver.containsProperty(key)) { |
| 67 |
5
1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → SURVIVED 2. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE 3. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT 4. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 5. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED |
return resolver.getProperty(key, defaultValue); |
| 68 | } | |
| 69 | } | |
| 70 |
5
1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE 2. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT 3. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 4. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 5. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED |
return defaultValue; |
| 71 | } | |
| 72 | ||
| 73 | @Override | |
| 74 | public <T> T getProperty(String key, Class<T> targetType) { | |
| 75 | for (PropertyResolver resolver : delegates) { | |
| 76 |
7
1. getProperty : negated conditional → NO_COVERAGE 2. getProperty : negated conditional → TIMED_OUT 3. getProperty : negated conditional → KILLED 4. getProperty : negated conditional → KILLED 5. getProperty : negated conditional → KILLED 6. getProperty : negated conditional → KILLED 7. getProperty : negated conditional → KILLED |
if (resolver.containsProperty(key)) { |
| 77 |
7
1. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE 2. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → TIMED_OUT 3. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 4. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 5. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 6. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED 7. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → KILLED |
return resolver.getProperty(key, targetType); |
| 78 | } | |
| 79 | } | |
| 80 | return null; | |
| 81 | } | |
| 82 | ||
| 83 | @Override | |
| 84 | public <T> T getProperty(String key, Class<T> targetType, T defaultValue) { | |
| 85 | for (PropertyResolver resolver : delegates) { | |
| 86 |
1
1. getProperty : negated conditional → NO_COVERAGE |
if (resolver.containsProperty(key)) { |
| 87 |
1
1. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE |
return resolver.getProperty(key, targetType, defaultValue); |
| 88 | } | |
| 89 | } | |
| 90 |
1
1. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE |
return defaultValue; |
| 91 | } | |
| 92 | ||
| 93 | @Override | |
| 94 | public String getRequiredProperty(String key) { | |
| 95 | for (PropertyResolver resolver : delegates) { | |
| 96 |
1
1. getRequiredProperty : negated conditional → NO_COVERAGE |
if (resolver.containsProperty(key)) { |
| 97 |
1
1. getRequiredProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getRequiredProperty → NO_COVERAGE |
return resolver.getRequiredProperty(key); |
| 98 | } | |
| 99 | } | |
| 100 | throw new IllegalStateException("no value for required property " + key); | |
| 101 | } | |
| 102 | ||
| 103 | @Override | |
| 104 | public <T> T getRequiredProperty(String key, Class<T> targetType) { | |
| 105 | for (PropertyResolver resolver : delegates) { | |
| 106 |
1
1. getRequiredProperty : negated conditional → NO_COVERAGE |
if (resolver.containsProperty(key)) { |
| 107 |
1
1. getRequiredProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getRequiredProperty → NO_COVERAGE |
return resolver.getRequiredProperty(key, targetType); |
| 108 | } | |
| 109 | } | |
| 110 | throw new IllegalStateException("no value for required property " + key); | |
| 111 | } | |
| 112 | ||
| 113 | } | |
Mutations | ||
| 46 |
1.1 2.2 3.3 4.4 |
|
| 47 |
1.1 2.2 3.3 |
|
| 50 |
1.1 2.2 3.3 4.4 |
|
| 56 |
1.1 2.2 3.3 4.4 |
|
| 57 |
1.1 2.2 3.3 4.4 |
|
| 60 |
1.1 2.2 3.3 4.4 5.5 |
|
| 66 |
1.1 2.2 3.3 4.4 |
|
| 67 |
1.1 2.2 3.3 4.4 5.5 |
|
| 70 |
1.1 2.2 3.3 4.4 5.5 |
|
| 76 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 77 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 90 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |