[Dive4elements-commits] [PATCH 09 of 19] RangeAccess.getKmRange: Extracted from FLYSUtils

Wald Commits scm-commit at wald.intevation.org
Thu Jan 24 14:14:21 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1358942292 -3600
# Node ID a0949259181e46382604493aa486450fa30e6a9d
# Parent  9790a284246c0e940815a43173fbd6049f550a15
RangeAccess.getKmRange: Extracted from FLYSUtils.

diff -r 9790a284246c -r a0949259181e flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/RangeAccess.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/RangeAccess.java	Wed Jan 23 12:27:00 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/RangeAccess.java	Wed Jan 23 12:58:12 2013 +0100
@@ -3,7 +3,6 @@
 import org.apache.log4j.Logger;
 
 import gnu.trove.TDoubleArrayList;
-
 import de.intevation.artifacts.CallContext;
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
@@ -149,7 +148,34 @@
      * (ld_from/to vs ld_locations).
      */
     public double[] getKmRange() {
-        return FLYSUtils.getKmRange(this.getArtifact());
+        // TODO store kmRange in field.
+        switch (getKmRangeMode()) {
+            case RANGE: {
+                return getKmFromTo();
+            }
+
+            case LOCATIONS: {
+                double[] locs = getLocations();
+                // if no locations, nPE.
+                if (locs == null) {
+                    logger.warn("no locations to get km range from.");
+                    return new double[] { Double.NaN, Double.NaN };
+                }
+                return new double[] { locs[0], locs[locs.length-1] };
+            }
+
+            case NONE: {
+                double[] locs = getLocations();
+                if (locs != null) {
+                    return new double[] { locs[0], locs[locs.length-1] };
+                }
+                else {
+                    return getKmFromTo();
+                }
+            }
+        }
+
+        return new double[] { Double.NaN, Double.NaN };
     }
 
 


More information about the Dive4elements-commits mailing list