FirstExistingPropertiesResolver.java

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 1 1. containsProperty : negated conditional → RUN_ERROR
			if (resolver.containsProperty(key)) {
47 1 1. containsProperty : replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → RUN_ERROR
				return true;
48
			}
49
		}
50 1 1. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → RUN_ERROR
		return false;
51
	}
52
53
	@Override
54
	public String getProperty(String key) {
55
		for (PropertyResolver resolver : delegates) {
56 1 1. getProperty : negated conditional → RUN_ERROR
			if (resolver.containsProperty(key)) {
57 1 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR
				return resolver.getProperty(key);
58
			}
59
		}
60 1 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR
		return null;
61
	}
62
63
	@Override
64
	public String getProperty(String key, String defaultValue) {
65
		for (PropertyResolver resolver : delegates) {
66 1 1. getProperty : negated conditional → RUN_ERROR
			if (resolver.containsProperty(key)) {
67 1 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR
				return resolver.getProperty(key, defaultValue);
68
			}
69
		}
70 1 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR
		return defaultValue;
71
	}
72
73
	@Override
74
	public <T> T getProperty(String key, Class<T> targetType) {
75
		for (PropertyResolver resolver : delegates) {
76 1 1. getProperty : negated conditional → RUN_ERROR
			if (resolver.containsProperty(key)) {
77 1 1. getProperty : replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR
				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
Location : containsProperty
Killed by :
negated conditional → RUN_ERROR

47

1.1
Location : containsProperty
Killed by :
replaced boolean return with false for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → RUN_ERROR

50

1.1
Location : containsProperty
Killed by :
replaced boolean return with true for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::containsProperty → RUN_ERROR

56

1.1
Location : getProperty
Killed by :
negated conditional → RUN_ERROR

57

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR

60

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR

66

1.1
Location : getProperty
Killed by :
negated conditional → RUN_ERROR

67

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR

70

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR

76

1.1
Location : getProperty
Killed by :
negated conditional → RUN_ERROR

77

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → RUN_ERROR

86

1.1
Location : getProperty
Killed by :
negated conditional → NO_COVERAGE

87

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

90

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getProperty → NO_COVERAGE

96

1.1
Location : getRequiredProperty
Killed by :
negated conditional → NO_COVERAGE

97

1.1
Location : getRequiredProperty
Killed by :
replaced return value with "" for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getRequiredProperty → NO_COVERAGE

106

1.1
Location : getRequiredProperty
Killed by :
negated conditional → NO_COVERAGE

107

1.1
Location : getRequiredProperty
Killed by :
replaced return value with null for fr/sii/ogham/core/env/FirstExistingPropertiesResolver::getRequiredProperty → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1