| 1 | package fr.sii.ogham.core.condition.provider; | |
| 2 | ||
| 3 | import static fr.sii.ogham.core.condition.fluent.Conditions.alwaysTrue; | |
| 4 | import static fr.sii.ogham.core.condition.fluent.Conditions.not; | |
| 5 | import static fr.sii.ogham.core.condition.fluent.Conditions.requiredClass; | |
| 6 | ||
| 7 | import fr.sii.ogham.core.builder.condition.RequiredClass; | |
| 8 | import fr.sii.ogham.core.condition.Condition; | |
| 9 | import fr.sii.ogham.core.condition.fluent.Conditions; | |
| 10 | import fr.sii.ogham.core.condition.fluent.FluentCondition; | |
| 11 | ||
| 12 | /** | |
| 13 | * Provider that handle {@link RequiredClass} annotation to provide a condition. | |
| 14 | * | |
| 15 | * @author Aurélien Baudet | |
| 16 | * | |
| 17 | * @param <T> | |
| 18 | * the kind of the object under conditions | |
| 19 | */ | |
| 20 | public class RequiredClassAnnotationProvider<T> implements ConditionProvider<RequiredClass, T> { | |
| 21 | ||
| 22 | @Override | |
| 23 | public Condition<T> provide(RequiredClass annotation) { | |
| 24 |
1
1. provide : negated conditional → RUN_ERROR |
if (annotation == null) { |
| 25 |
1
1. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredClassAnnotationProvider::provide → RUN_ERROR |
return alwaysTrue(); |
| 26 | } else { | |
| 27 | FluentCondition<T> mainCondition = classNameOrAlternatives(annotation); | |
| 28 | for (String exclude : annotation.excludes()) { | |
| 29 | mainCondition = mainCondition.and(not(Conditions.<T> requiredClass(exclude))); | |
| 30 | } | |
| 31 |
1
1. provide : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredClassAnnotationProvider::provide → RUN_ERROR |
return mainCondition; |
| 32 | } | |
| 33 | } | |
| 34 | ||
| 35 | private FluentCondition<T> classNameOrAlternatives(RequiredClass annotation) { | |
| 36 | FluentCondition<T> condition = requiredClass(annotation.value()); | |
| 37 | for (String alternative : annotation.alternatives()) { | |
| 38 | condition = condition.or(Conditions.<T> requiredClass(alternative)); | |
| 39 | } | |
| 40 |
1
1. classNameOrAlternatives : replaced return value with null for fr/sii/ogham/core/condition/provider/RequiredClassAnnotationProvider::classNameOrAlternatives → RUN_ERROR |
return condition; |
| 41 | } | |
| 42 | ||
| 43 | } | |
Mutations | ||
| 24 |
1.1 |
|
| 25 |
1.1 |
|
| 31 |
1.1 |
|
| 40 |
1.1 |