changeset 9132:8cc192731c7d

WQSelect can now handle distance-only data
author gernotbelger
date Wed, 06 Jun 2018 14:24:51 +0200
parents 0a19a79663dd
children af73fdd96920 0f7364772dd1
files artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/access/DGMAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java
diffstat 5 files changed, 55 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -54,6 +54,26 @@
         }
     }
 
+    public final double getStartKm() {
+
+        final KM_MODE mode = getKmRangeMode();
+        switch (mode) {
+        case RANGE:
+        case DISTANCE_ONLY:
+            return getFrom();
+
+        case LOCATIONS:
+        case NONE:
+        default:
+            final double[] locations = getLocations();
+            if( locations != null && locations.length > 0 )
+                // TODO: this is the old behaviour, but what happens if the user enters the values unsorted?
+                return locations[0];
+
+            return Double.NaN;
+        }
+    }
+
     public double[] getKms() {
 
         if (isRange())
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/DGMAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/DGMAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -18,9 +18,6 @@
 
     private String geoJSON;
 
-    public DGMAccess() {
-    }
-
     public DGMAccess(D4EArtifact artifact) {
         super(artifact);
     }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -23,49 +23,55 @@
     private static Logger log = Logger.getLogger(RangeAccess.class);
 
     public static enum KM_MODE {
-        RANGE, LOCATIONS, NONE
-    };
+        RANGE, LOCATIONS, NONE, DISTANCE_ONLY
+    }
 
     /** The default step width between the start end end kilometer. */
     public static final double DEFAULT_KM_STEPS = 0.1;
 
-    double[] kmRange;
+    private Double from;
 
-    Double from;
+    private Double to;
 
-    Double to;
-
-    Double step;
+    private Double step;
 
     private KM_MODE mode;
 
-    public RangeAccess() {
-    }
-
     public RangeAccess(final D4EArtifact artifact) {
         super(artifact);
     }
 
     /** Evaluate the ld_mode data of artifact. */
     public KM_MODE getKmRangeMode() {
-        if (this.mode != null) {
+        if (this.mode != null)
             return this.mode;
-        }
-        final String modeData = getString("ld_mode");
 
-        if (modeData == null || modeData.length() == 0) {
-            this.mode = KM_MODE.NONE;
-        } else if (modeData.equals("distance")) {
-            this.mode = KM_MODE.RANGE;
-        } else if (modeData.equals("locations")) {
-            this.mode = KM_MODE.LOCATIONS;
-        } else {
-            this.mode = KM_MODE.NONE;
-        }
+        final String modeData = getString("ld_mode");
+        this.mode = parseRangeMode(modeData);
 
         return this.mode;
     }
 
+    private KM_MODE parseRangeMode(final String modeData) {
+
+        if (modeData == null)
+            return KM_MODE.NONE;
+
+        switch (modeData) {
+        case "distance":
+            return KM_MODE.RANGE;
+
+        case "distance_only":
+            return KM_MODE.DISTANCE_ONLY;
+
+        case "locations":
+            return KM_MODE.LOCATIONS;
+
+        default:
+            return KM_MODE.NONE;
+        }
+    }
+
     public final DoubleRange getRange() {
         final double from = getFrom();
         final double to = getTo();
@@ -204,9 +210,9 @@
     public double[] getKmRange() {
         // TODO store kmRange in field.
         switch (getKmRangeMode()) {
-        case RANGE: {
+        case RANGE:
+        case DISTANCE_ONLY:
             return getKmFromTo();
-        }
 
         case LOCATIONS: {
             final double[] locs = getLocations();
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -24,11 +24,7 @@
     private static Logger log = Logger.getLogger(RiverAccess.class);
 
     /** River name. */
-    protected String river;
-
-
-    public RiverAccess() {
-    }
+    private String river;
 
     public RiverAccess(D4EArtifact artifact) {
         super(artifact);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java	Wed Jun 06 14:17:18 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java	Wed Jun 06 14:24:51 2018 +0200
@@ -22,18 +22,15 @@
 {
     private static Logger log = Logger.getLogger(SQRelationAccess.class);
 
-    protected Double    location;
+    private Double    location;
 
-    protected DateRange period;
+    private DateRange period;
 
-    protected Double    outliers;
+    private Double    outliers;
 
     private String      method;
 
-    protected MeasurementStation measurementStation;
-
-    public SQRelationAccess() {
-    }
+    private MeasurementStation measurementStation;
 
     public SQRelationAccess(D4EArtifact artifact) {
         super(artifact);

http://dive4elements.wald.intevation.org