OrCondition.java

1
package fr.sii.ogham.core.condition;
2
3
import java.util.List;
4
5
import fr.sii.ogham.core.util.StringUtils;
6
7
/**
8
 * Condition that provides a logical OR operation on manipulated conditions.
9
 * 
10
 * @author Aurélien Baudet
11
 *
12
 * @param <T>
13
 *            the type of the object to test
14
 */
15
public class OrCondition<T> extends CompositeCondition<T> {
16
17
	/**
18
	 * Initializes the {@code or} operator with none, one or several
19
	 * sub-conditions.
20
	 * 
21
	 * <pre>
22
	 * Condition&lt;String&gt; condition1 = ...
23
	 * Condition&lt;String&gt; condition2 = ...
24
	 * OrCondition&lt;String&gt; myCondition = new OrCondition&lt;&gt;(condition1, condition2);
25
	 * </pre>
26
	 * 
27
	 * Has the same effect as:
28
	 * 
29
	 * <pre>
30
	 * Condition&lt;String&gt; condition1 = ...
31
	 * Condition&lt;String&gt; condition2 = ...
32
	 * OrCondition&lt;String&gt; myCondition = new OrCondition&lt;&gt;();
33
	 * myCondition.or(condition1);
34
	 * myCondition.or(condition2);
35
	 * </pre>
36
	 * 
37
	 * @param conditions
38
	 *            the conditions to register (order is important)
39
	 */
40
	@SafeVarargs
41
	public OrCondition(Condition<T>... conditions) {
42
		super(conditions);
43
	}
44
45
	/**
46
	 * Initializes the {@code or} operator with none, one or several
47
	 * sub-conditions. The list must not be null.
48
	 * 
49
	 * @param conditions
50
	 *            the conditions to register (order is important)
51
	 */
52
	public OrCondition(List<Condition<T>> conditions) {
53
		super(conditions);
54
	}
55
56
	@Override
57
	public boolean accept(T obj) {
58
		for (Condition<T> condition : getConditions()) {
59
			// if the condition accepts the object => stop now
60 5 1. accept : negated conditional → NO_COVERAGE
2. accept : negated conditional → TIMED_OUT
3. accept : negated conditional → KILLED
4. accept : negated conditional → KILLED
5. accept : negated conditional → KILLED
			if (condition.accept(obj)) {
61 5 1. accept : replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → NO_COVERAGE
2. accept : replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → TIMED_OUT
3. accept : replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → KILLED
4. accept : replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → KILLED
5. accept : replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → KILLED
				return true;
62
			}
63
		}
64
		// none condition has accepted the object => it is rejected
65 4 1. accept : replaced boolean return with true for fr/sii/ogham/core/condition/OrCondition::accept → NO_COVERAGE
2. accept : replaced boolean return with true for fr/sii/ogham/core/condition/OrCondition::accept → KILLED
3. accept : replaced boolean return with true for fr/sii/ogham/core/condition/OrCondition::accept → KILLED
4. accept : replaced boolean return with true for fr/sii/ogham/core/condition/OrCondition::accept → KILLED
		return false;
66
	}
67
68
	/**
69
	 * Adds a condition to the current condition. For example:
70
	 * 
71
	 * <pre>
72
	 * OrCondition&lt;String&gt; myCondition = new OrCondition&lt;&gt;();
73
	 * myCondition.or(new FixedCondition&lt;&gt;(true));
74
	 * myCondition.apply("foo"); // will always return true
75
	 * 
76
	 * myCondition.or(new FixedCondition&lt;&gt;(false));
77
	 * myCondition.apply("foo"); // will always return false
78
	 * </pre>
79
	 * 
80
	 * The returned instance is the same as {@code myCondition} so you can also
81
	 * write this:
82
	 * 
83
	 * <pre>
84
	 * OrCondition&lt;String&gt; myCondition = new OrCondition&lt;&gt;();
85
	 * myCondition = myCondition.or(new FixedCondition&lt;&gt;(true));
86
	 * myCondition.apply("foo"); // will always return true
87
	 * 
88
	 * myCondition = myCondition.or(new FixedCondition&lt;&gt;(false));
89
	 * myCondition.apply("foo"); // will always return true because first
90
	 * 							// condition always returns true
91
	 * </pre>
92
	 * 
93
	 * 
94
	 * @param condition
95
	 *            the condition to add
96
	 * @return this instance for fluent chaining
97
	 */
98
	public OrCondition<T> or(Condition<T> condition) {
99
		addCondition(condition);
100 1 1. or : replaced return value with null for fr/sii/ogham/core/condition/OrCondition::or → NO_COVERAGE
		return this;
101
	}
102
103
	/**
104
	 * Adds several conditions at once to the current condition. This can be
105
	 * useful when you register each sub-condition into a list:
106
	 * 
107
	 * <pre>
108
	 * List&lt;Condition&lt;String&gt;&gt; conditions = new ArrayList&lt;&gt;();
109
	 * conditions.add(...);
110
	 * conditions.add(...);
111
	 * OrCondition&lt;String&gt; myCondition = new OrCondition&lt;&gt;();
112
	 * myCondition.or(conditions);
113
	 * </pre>
114
	 * 
115
	 * @param conditions
116
	 *            the list of conditions to register
117
	 * @return this instance for fluent chaining
118
	 */
119
	public OrCondition<T> or(List<Condition<T>> conditions) {
120
		addConditions(conditions);
121 1 1. or : replaced return value with null for fr/sii/ogham/core/condition/OrCondition::or → NO_COVERAGE
		return this;
122
	}
123
124
	@Override
125
	public String toString() {
126 1 1. toString : replaced return value with "" for fr/sii/ogham/core/condition/OrCondition::toString → NO_COVERAGE
		return "{" + StringUtils.join(conditions, " or ") + "}";
127
	}
128
}

Mutations

60

1.1
Location : accept
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

2.2
Location : accept
Killed by : oghamcore.ut.core.condition.fluent.FluentConditionsTest.requiredMailHostOrMailSmtpHostProperties(oghamcore.ut.core.condition.fluent.FluentConditionsTest)
negated conditional → KILLED

3.3
Location : accept
Killed by : none
negated conditional → TIMED_OUT

4.4
Location : accept
Killed by : none
negated conditional → NO_COVERAGE

5.5
Location : accept
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
negated conditional → KILLED

61

1.1
Location : accept
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → KILLED

2.2
Location : accept
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → NO_COVERAGE

3.3
Location : accept
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.oghamPropertyShouldOverride(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → KILLED

4.4
Location : accept
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → TIMED_OUT

5.5
Location : accept
Killed by : oghamcore.ut.core.condition.fluent.FluentConditionsTest.requiredMailHostOrMailSmtpHostProperties(oghamcore.ut.core.condition.fluent.FluentConditionsTest)
replaced boolean return with false for fr/sii/ogham/core/condition/OrCondition::accept → KILLED

65

1.1
Location : accept
Killed by : oghamcore.ut.core.condition.fluent.FluentConditionsTest.requiredMailHostOrMailSmtpHostProperties(oghamcore.ut.core.condition.fluent.FluentConditionsTest)
replaced boolean return with true for fr/sii/ogham/core/condition/OrCondition::accept → KILLED

2.2
Location : accept
Killed by : oghamall.it.email.EmailCustomImplTest.simple(oghamall.it.email.EmailCustomImplTest)
replaced boolean return with true for fr/sii/ogham/core/condition/OrCondition::accept → KILLED

3.3
Location : accept
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/condition/OrCondition::accept → NO_COVERAGE

4.4
Location : accept
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
replaced boolean return with true for fr/sii/ogham/core/condition/OrCondition::accept → KILLED

100

1.1
Location : or
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/OrCondition::or → NO_COVERAGE

121

1.1
Location : or
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/OrCondition::or → NO_COVERAGE

126

1.1
Location : toString
Killed by : none
replaced return value with "" for fr/sii/ogham/core/condition/OrCondition::toString → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM