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