changeset 2235:ee5310134463

Cosmetics/care/refac. flys-artifacts/trunk@3879 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 02 Feb 2012 13:23:55 +0000
parents 46ec09c7f578
children c2b15d9c0f43
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java
diffstat 6 files changed, 51 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Feb 02 12:50:33 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Feb 02 13:23:55 2012 +0000
@@ -1,3 +1,18 @@
+2012-02-02  Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java:
+	  Refactored. Use supers static field.
+
+	* src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java:
+	  Refactored. Use static field.
+
+	* src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java,
+	  src/main/java/de/intevation/flys/utils/FLYSUtils.java
+	  (getMinMax, getRiverMinMax): Refactored. Moved to FLYSUtils.
+	
+	* src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java:
+	  Add so-called javadoc.
+
 2012-02-02  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java	Thu Feb 02 12:50:33 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java	Thu Feb 02 13:23:55 2012 +0000
@@ -33,6 +33,9 @@
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.resources.Resources;
 
+import de.intevation.flys.utils.FLYSUtils;
+
+
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
@@ -235,15 +238,7 @@
     @Override
     protected double[] getMinMax(Artifact artifact) {
         FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
-        StateData    data         = getData(flysArtifact, "river");
-
-        String name = data != null ? (String) data.getValue() : "";
-
-        logger.debug("Search for the min/max distances of '" + name + "'");
-
-        River river = RiverFactory.getRiver(name);
-
-        return river != null ? river.determineMinMaxDistance() : null;
+        return FLYSUtils.getRiverMinMax(flysArtifact);
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java	Thu Feb 02 12:50:33 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java	Thu Feb 02 13:23:55 2012 +0000
@@ -24,7 +24,7 @@
     /** The name of the 'mode' field. */
     public static final String MODE = "ld_mode";
 
-    /** The name of the 'locations' field.*/
+    /** The name of the 'locations' field. */
     public static final String LOCATIONS = "ld_locations";
 
 
@@ -119,7 +119,7 @@
 
 
     public static double[] getLocations(WINFOArtifact flys) {
-        StateData data  = flys.getData("ld_locations");
+        StateData data  = flys.getData(LOCATIONS);
         String    value = data != null ? (String) data.getValue() : null;
 
         if (value == null || value.length() == 0) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java	Thu Feb 02 12:50:33 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java	Thu Feb 02 13:23:55 2012 +0000
@@ -28,9 +28,6 @@
     /** The logger used in this class.*/
     private static Logger logger = Logger.getLogger(LocationSelect.class);
 
-    /** The name of the StateData object that stores the location string.*/
-    public static final String FIELD_LOCATIONS = "ld_locations";
-
 
     public LocationSelect() {
     }
@@ -62,7 +59,7 @@
             logger.warn("Could not read min/max distance values!");
         }
 
-        if (name.equals(FIELD_LOCATIONS)) {
+        if (name.equals(LOCATIONS)) {
             Element min = createItem(
                 cr,
                 new String[] {"min", new Double(minVal).toString()});
@@ -85,7 +82,7 @@
         logger.debug("LocationSelect.validate");
 
         FLYSArtifact flys = (FLYSArtifact) artifact;
-        StateData    data = getData(flys, FIELD_LOCATIONS);
+        StateData    data = getData(flys, LOCATIONS);
 
         String locationStr = data != null
             ? (String) data.getValue()
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java	Thu Feb 02 12:50:33 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java	Thu Feb 02 13:23:55 2012 +0000
@@ -16,6 +16,8 @@
 
 
 /**
+ * State that holds minimun and maximum (for validation).
+ *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public abstract class MinMaxState extends DefaultState {
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Thu Feb 02 12:50:33 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Thu Feb 02 13:23:55 2012 +0000
@@ -233,6 +233,32 @@
     }
 
 
+    /**
+     * Get bounds for river of artifact.
+     * @param flysArtifact artifact which has a "river" data.
+     * @return double array. min is at[0], max at[1]. null if given artifact is null
+     */
+    public static double[] getRiverMinMax(FLYSArtifact flysArtifact) {
+        if (flysArtifact == null) {
+            return null;
+        }
+
+        String riverName = flysArtifact.getDataAsString("river");
+
+        if (riverName == null) {
+            riverName = "";
+        }
+
+        logger.debug("Search for the min/max distances of '" + riverName + "'");
+
+        River river = RiverFactory.getRiver(riverName);
+
+        return river != null
+            ? river.determineMinMaxDistance()
+            : null;
+    }
+
+
     public static double[] getKmFromTo(FLYSArtifact flys) {
         String strFrom = flys.getDataAsString("ld_from");
         String strTo   = flys.getDataAsString("ld_to");

http://dive4elements.wald.intevation.org