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