changeset 4853:a0949259181e

RangeAccess.getKmRange: Extracted from FLYSUtils.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 23 Jan 2013 12:58:12 +0100
parents 9790a284246c
children c53b3fdc9821
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/RangeAccess.java
diffstat 1 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 };
     }
 
 

http://dive4elements.wald.intevation.org