This is an automated email from the git hooks/post-receive script. New commit to branch feature/6392 in repository wao. See http://git.codelutin.com/wao.git commit 6fa7fe7c1a598b557a90ee49d6c2a6fcd256a824 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Feb 26 14:11:16 2015 +0100 Extraction, dans WaoUtils, de la méthode permettant de déduire le mois sur lequel compter le contact ObsMer --- .../src/main/java/fr/ifremer/wao/WaoUtils.java | 17 +++++++++++++++++ .../wao/services/service/ObsMerSamplingPlanBuilder.java | 10 +--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java b/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java index 0f6a1ce..0c1ebfd 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/WaoUtils.java @@ -274,4 +274,21 @@ public class WaoUtils { } }; } + + /** + * Retourne la clé qui a la plus grande valeur, en présences des valeurs égales, on privilégie + * les premières clés trouvées. + */ + public static <T> T getKeyWithHighestValue(Map<T, Integer> map) { + T keyWithHighestValue = null; + int maxObservationDays = 0; + for (Map.Entry<T, Integer> entry : map.entrySet()) { + T aKey = entry.getKey(); + Integer aObservationDays = entry.getValue(); + if (aObservationDays > maxObservationDays) { + keyWithHighestValue = aKey; + } + } + return keyWithHighestValue; + } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java index b7ae22c..cc7758d 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java @@ -137,15 +137,7 @@ public class ObsMerSamplingPlanBuilder { doneObservation.getObservationEndDate()); // on en déduit le mois sur lequel il faut compter l'observation - Date month = null; - int maxObservationDays = 0; - for (Map.Entry<Date, Integer> entry : observationDaysByMonthsForObservation.entrySet()) { - Date aMonth = entry.getKey(); - Integer aObservationDays = entry.getValue(); - if (aObservationDays > maxObservationDays) { - month = aMonth; - } - } + Date month = WaoUtils.getKeyWithHighestValue(observationDaysByMonthsForObservation); if (log.isDebugEnabled()) { log.debug("contact " + doneObservation + " will be added to month " + month); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.