From e7e60d0435b3fab7fd2566e11a9afb644f292d1c Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Mon, 12 Feb 2024 10:44:17 +0100 Subject: [PATCH 1/2] Renommer CompositeIndicator.toAggregate(boolean). fixes #8 --- .../agroclim/indicators/model/Evaluation.java | 2 +- .../model/indicator/CompositeIndicator.java | 56 +++++++++++-------- .../indicators/model/EvaluationTest.java | 8 +-- .../EvaluationWithoutAggregationTest.java | 8 +-- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/main/java/fr/inrae/agroclim/indicators/model/Evaluation.java b/src/main/java/fr/inrae/agroclim/indicators/model/Evaluation.java index 2648642c..fb76b985 100644 --- a/src/main/java/fr/inrae/agroclim/indicators/model/Evaluation.java +++ b/src/main/java/fr/inrae/agroclim/indicators/model/Evaluation.java @@ -840,7 +840,7 @@ public final class Evaluation extends CompositeIndicator { */ public boolean isOnErrorOrIncomplete(final boolean fire) { final boolean hasClimaticIndicator = containsClimaticIndicator(fire); - final boolean isToAggregate = toAggregate(fire); + final boolean isToAggregate = isAggregationMissing(fire); final boolean isComputable = isComputable(); return !hasClimaticIndicator || isToAggregate || !isComputable; diff --git a/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java b/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java index 1de20057..a84fe948 100644 --- a/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java +++ b/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java @@ -478,6 +478,36 @@ DataLoadingListener, Detailable, HasDataLoadingListener, Comparable<Indicator> { .forEach(ind -> ((CompositeIndicator) ind).initializeParent()); } + /** + * Detect if aggregation function is needed but missing. + * + * @param fire fire events while checking + * @return true if aggregation function is needed but missing + */ + public final boolean isAggregationMissing(boolean fire) { + if (getType() == EvaluationType.WITHOUT_AGGREGATION) { + return false; + } + boolean isMissing = false; + final AggregationFunction aggregation = getAggregationFunction(); + if (isAggregationNeeded() + && (aggregation == null || !aggregation.isValid())) { + if (fire) { + fireIndicatorEvent(IndicatorEvent.Type.AGGREGATION_MISSING + .event(this)); + } + isMissing = true; + } + + for (final Indicator indicator : getIndicators()) { + if (indicator instanceof CompositeIndicator compositeIndicator + && compositeIndicator.isAggregationMissing(fire)) { + isMissing = true; + } + } + return isMissing; + } + /** * @return if aggregation is needed, according to category and number of * composed indicators @@ -588,7 +618,7 @@ DataLoadingListener, Detailable, HasDataLoadingListener, Comparable<Indicator> { fireAggregationFunctionUpdated(); } fireIndicatorEvent(IndicatorEvent.Type.REMOVE.event(i)); - toAggregate(true); + isAggregationMissing(true); if (!containsClimaticIndicator()) { /* Ne contient pas d'indicateur climatique */ fireIndicatorEvent( @@ -619,29 +649,11 @@ DataLoadingListener, Detailable, HasDataLoadingListener, Comparable<Indicator> { * * @param fire fire events while checking * @return true if aggregation function is needed but missing + * @deprecated use {@link CompositeIndicator#isAggregationMissing(boolean)}. */ + @Deprecated(since = "2.0.1", forRemoval = true) public final boolean toAggregate(final boolean fire) { - if (getType() == EvaluationType.WITHOUT_AGGREGATION) { - return false; - } - boolean toAggregate = false; - final AggregationFunction aggregation = getAggregationFunction(); - if (isAggregationNeeded() - && (aggregation == null || !aggregation.isValid())) { - if (fire) { - fireIndicatorEvent(IndicatorEvent.Type.AGGREGATION_MISSING - .event(this)); - } - toAggregate = true; - } - - for (final Indicator indicator : getIndicators()) { - if (indicator instanceof CompositeIndicator compositeIndicator - && compositeIndicator.toAggregate(fire)) { - toAggregate = true; - } - } - return toAggregate; + return isAggregationMissing(fire); } @Override diff --git a/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationTest.java b/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationTest.java index a7bf99dd..a3f975d4 100644 --- a/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationTest.java +++ b/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationTest.java @@ -449,14 +449,14 @@ public final class EvaluationTest extends DataTestHelper { } /** - * Test toAggregate(). + * Test isAggregationMissing(). */ @Test - public void toAggregate() { + public void isAggregationMissing() { assertTrue("Evaluation must not be null!", evaluation != null); - boolean found = evaluation.toAggregate(false); + boolean found = evaluation.isAggregationMissing(false); assertFalse("evaluation do not need to be aggregated!", found); - found = evaluation.toAggregate(true); + found = evaluation.isAggregationMissing(true); assertFalse("evaluation do not need to be aggregated!", found); } diff --git a/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationWithoutAggregationTest.java b/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationWithoutAggregationTest.java index 6bc18824..2394bd37 100644 --- a/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationWithoutAggregationTest.java +++ b/src/test/java/fr/inrae/agroclim/indicators/model/EvaluationWithoutAggregationTest.java @@ -138,14 +138,14 @@ public class EvaluationWithoutAggregationTest extends DataTestHelper { } /** - * Test toAggregate(). + * Test isAggregationMissing(). */ @Test - public void toAggregate() { + public void isAggregationMissing() { assertNotNull("Evaluation must not be null!", evaluation); - boolean found = evaluation.toAggregate(false); + boolean found = evaluation.isAggregationMissing(false); assertFalse("evaluation do not need to be aggregated!", found); - found = evaluation.toAggregate(true); + found = evaluation.isAggregationMissing(true); assertFalse("evaluation do not need to be aggregated!", found); } -- GitLab From 3686fda9205d27d564280a74b1f218afbf963dc0 Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Mon, 12 Feb 2024 10:47:02 +0100 Subject: [PATCH 2/2] Checkstyle --- .../agroclim/indicators/model/indicator/CompositeIndicator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java b/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java index a84fe948..173d70ba 100644 --- a/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java +++ b/src/main/java/fr/inrae/agroclim/indicators/model/indicator/CompositeIndicator.java @@ -484,7 +484,7 @@ DataLoadingListener, Detailable, HasDataLoadingListener, Comparable<Indicator> { * @param fire fire events while checking * @return true if aggregation function is needed but missing */ - public final boolean isAggregationMissing(boolean fire) { + public final boolean isAggregationMissing(final boolean fire) { if (getType() == EvaluationType.WITHOUT_AGGREGATION) { return false; } -- GitLab