[PATCH 1 of 9] Handle surprising filter behaivor of *Overviews. Don't create items for unavailable data

Wald Commits scm-commit at wald.intevation.org
Thu Mar 26 12:11:55 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1427364373 -3600
# Node ID 124efb3eea94350e68959c5844072b3d0e6abbf2
# Parent  1125e598df0e3716a8a6567f2aa9f0bc3ede114b
Handle surprising filter behaivor of *Overviews. Don't create items for unavailable data.

diff -r 1125e598df0e -r 124efb3eea94 artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java	Wed Mar 25 19:37:44 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java	Thu Mar 26 11:06:13 2015 +0100
@@ -30,6 +30,7 @@
 import org.dive4elements.artifacts.CallContext;
 
 import org.dive4elements.artifactdatabase.data.StateData;
+import org.dive4elements.river.backend.utils.EpsilonComparator;
 
 public class SQPeriodSelect extends PeriodsSelect {
 
@@ -40,7 +41,7 @@
     private static final long serialVersionUID = 1L;
 
     /** Get either the start date of the data or the end. */
-    protected long getDataMinMaxDate(Artifact artifact, boolean minDate) {
+    protected Long getDataMinMaxDate(Artifact artifact, boolean minDate) {
         D4EArtifact arti = (D4EArtifact) artifact;
         RangeAccess access = new RangeAccess(arti);
         double km = access.getLocations()[0];
@@ -49,11 +50,18 @@
          * in the next state anyway. */
         SQOverview overview = SQOverviewFactory.getOverview(access.getRiverName());
 
-        KMIndex<List<Date>> entries = overview.filter(new KmFilter(km));
+        /* Filter is not implemented and only checks if a complete
+         * KMIndex list is acceptable or not. So KMFiltering wont work */
+        KMIndex<List<Date>> entries = overview.filter(SQOverview.ACCEPT);
         TreeSet<Date> allDates = new TreeSet<Date>();
 
         for (int i = 0; i < entries.size(); i++) {
-            allDates.addAll(entries.get(i).getValue());
+            if (EpsilonComparator.CMP.compare(entries.get(i).getKm(), km) == 0) {
+                allDates.addAll(entries.get(i).getValue());
+            }
+        }
+        if (allDates.size() < 2) {
+            return null;
         }
 
         return minDate ? allDates.first().getTime() : allDates.last().getTime();
@@ -69,10 +77,13 @@
         if (!name.equals("start") && !name.equals("end")) {
             return null;
         }
+        Long value = getDataMinMaxDate(artifact, name.equals("start"));
+        if (value == null) {
+            return null;
+        }
         Element def = createItem(
             cr,
-            new String[] {"default", Long.toString(
-                getDataMinMaxDate(artifact, name.equals("start")))});
+            new String[] {"default", value.toString()});
 
         return new Element[] { def };
     }


More information about the Dive4Elements-commits mailing list