diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 1095:f465785ed1ae

Refactored the code to fetch the km range/locations into a utility class. flys-artifacts/trunk@2598 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 26 Aug 2011 14:58:35 +0000
parents 61c051e53f9b
children 7bd514eb4b2c
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Aug 26 14:55:18 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Aug 26 14:58:35 2011 +0000
@@ -40,6 +40,7 @@
 import de.intevation.flys.model.River;
 
 import de.intevation.flys.utils.DoubleUtil;
+import de.intevation.flys.utils.FLYSUtils;
 
 import gnu.trove.TDoubleArrayList;
 
@@ -321,7 +322,7 @@
         }
 
 
-        double [] range = getDistance();
+        double [] range = FLYSUtils.getKmRange(this);
         if (range == null) {
             return error(new WQKms[0], "No range found");
         }
@@ -393,7 +394,7 @@
            return error(null, "Cannot determine gauge.");
         }
 
-        double[] locations = getLocations();
+        double[] locations = FLYSUtils.getLocations(this);
 
         if (locations == null) {
             return error(null, "Cannot determine location.");
@@ -445,7 +446,7 @@
             return error(new WQKms[0], "no river found");
         }
 
-        double [] distance = getDistance();
+        double [] distance = FLYSUtils.getKmRange(this);
 
         if (distance == null) {
             return error(new WQKms[0], "no range found");
@@ -502,7 +503,7 @@
             return error(new WQKms[0], "Cannot determine river.");
         }
 
-        double[] locations = getLocations();
+        double[] locations = FLYSUtils.getLocations(this);
 
         if (locations == null) {
             return error(new WQKms[0], "Cannot determine location.");
@@ -619,7 +620,7 @@
             return null;
         }
 
-        double [] range = getDistance();
+        double [] range = FLYSUtils.getKmRange(this);
         if (range == null) {
             logger.warn("no ranges found");
             return null;
@@ -669,44 +670,6 @@
             : null;
     }
 
-
-    /**
-     * Returns the selected distance of points.
-     *
-     * @return the selected distance or points.
-     */
-    public double[] getDistance() {
-        StateData dMode      = getData("ld_mode");
-        StateData dFrom      = getData("ld_from");
-        StateData dTo        = getData("ld_to");
-        StateData dLocations = getData("ld_locations");
-
-        if (dMode != null) {
-            String mode = (String)dMode.getValue();
-            if ("location".equals(mode)) {
-                double[] locations = getLocations();
-                return new double[] { locations[0], locations[locations.length-1] };
-            }
-            if (dFrom != null && dTo != null) {
-                return getDistanceByRange(dFrom, dTo);
-            }
-        }
-
-        if (dLocations != null) {
-            double[] locations = getLocations();
-            return new double[] { locations[0], locations[locations.length-1] };
-        }
-
-        if (dFrom != null && dTo != null) {
-            return getDistanceByRange(dFrom, dTo);
-        }
-
-        logger.warn("No data found for distance determination!");
-
-        return null;
-    }
-
-
     /**
      * Determines the selected mode of distance/range input.
      *
@@ -727,42 +690,6 @@
 
 
     /**
-     * Returns the selected locations based on a given array of locations.
-     *
-     * @param locations The StateData that contains the locations.
-     *
-     * @return the selected locations.
-     */
-    public double[] getLocations() {
-        StateData dLocations  = getData("ld_locations");
-        String    locationStr = dLocations != null
-            ? (String) dLocations.getValue()
-            : "";
-
-        if (locationStr == null || locationStr.length() == 0) {
-            logger.warn("No valid location string found!");
-            return null;
-        }
-
-        String[] tmp               = locationStr.split(" ");
-        TDoubleArrayList locations = new TDoubleArrayList();
-
-        for (String l: tmp) {
-            try {
-                locations.add(Double.parseDouble(l));
-            }
-            catch (NumberFormatException nfe) {
-                logger.warn(nfe, nfe);
-            }
-        }
-
-        locations.sort();
-
-        return locations.toNativeArray();
-    }
-
-
-    /**
      * Returns the selected distance based on a given range (from, to).
      *
      * @param dFrom The StateData that contains the lower value.
@@ -813,7 +740,7 @@
      */
     public double[] getKms() {
         if (isRange()) {
-            double[] distance = getDistance();
+            double[] distance = FLYSUtils.getKmRange(this);
             return getKms(distance);
 
         }
@@ -826,7 +753,7 @@
         if (!isRange()) {
             return null;
         }
-        double [] fromTo = getDistance();
+        double [] fromTo = FLYSUtils.getKmRange(this);
 
         if (fromTo == null) {
             return null;
@@ -866,7 +793,7 @@
             return null;
         }
 
-        double[] dist  = getDistance();
+        double[] dist  = FLYSUtils.getKmRange(this);
 
         if (dist == null) {
             logger.debug("no range found");
@@ -900,7 +827,7 @@
             return null;
         }
 
-        double [] dist  = getDistance();
+        double [] dist  = FLYSUtils.getKmRange(this);
         if (dist == null) {
             return null;
         }

http://dive4elements.wald.intevation.org