diff artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java @ 9132:8cc192731c7d

WQSelect can now handle distance-only data
author gernotbelger
date Wed, 06 Jun 2018 14:24:51 +0200
parents 850ce16034e9
children
line wrap: on
line diff
--- 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();

http://dive4elements.wald.intevation.org