changeset 8621:1125e598df0e

Fix handling of multiple entries in SQPeriodSelect default start/end calculation
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 25 Mar 2015 19:37:44 +0100
parents 8737de2ca763
children 124efb3eea94
files artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java
diffstat 1 files changed, 6 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java	Wed Mar 25 19:20:13 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java	Wed Mar 25 19:37:44 2015 +0100
@@ -10,7 +10,7 @@
 
 import java.util.Date;
 import java.util.List;
-import java.util.Collections;
+import java.util.TreeSet;
 
 import org.apache.log4j.Logger;
 
@@ -50,16 +50,13 @@
         SQOverview overview = SQOverviewFactory.getOverview(access.getRiverName());
 
         KMIndex<List<Date>> entries = overview.filter(new KmFilter(km));
-        if (entries.size() == 0) {
-            return 0;
+        TreeSet<Date> allDates = new TreeSet<Date>();
+
+        for (int i = 0; i < entries.size(); i++) {
+            allDates.addAll(entries.get(i).getValue());
         }
-        List<Date> dates = entries.get(0).getValue();
-        if (dates.isEmpty()) {
-            return 0;
-        }
-        Collections.sort(dates);
 
-        return minDate ? dates.get(0).getTime() : dates.get(dates.size() - 1).getTime();
+        return minDate ? allDates.first().getTime() : allDates.last().getTime();
     }
 
     @Override

http://dive4elements.wald.intevation.org