changeset 1279:af6ad7522351

Bugfix: #336 Improved determination of min/max KM values - code moved to ArtifactDescription. flys-client/trunk@2861 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 29 Sep 2011 09:14:41 +0000
parents 4c3329db2536
children 66192d170c79
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultArtifactDescription.java
diffstat 5 files changed, 150 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Sep 28 14:03:31 2011 +0000
+++ b/flys-client/ChangeLog	Thu Sep 29 09:14:41 2011 +0000
@@ -1,3 +1,19 @@
+2011-09-29  Ingo Weinzierl <ingo@intevation.de>
+
+	flys/issue336 (W-INFO / Berechnung Wasserstand an Orten, Zurodnung Bezugspegel)
+
+	* src/main/java/de/intevation/flys/client/shared/model/DefaultArtifactDescription.java,
+	  src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java:
+	  Added two new methods getRiver() (returns the selected river) and
+	  getKMRange() (returns the selected min/max KM values).
+
+	* src/main/java/de/intevation/flys/client/shared/DoubleUtils.java: New.
+	  Utility class for working with double values.
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java:
+	  Moved the code to determine the min/max KM range and river out to
+	  ArtifactDescription. There, it is available for other classes as well.
+
 2011-09-28  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue328 (W-INFO / ÜSK: Auswahl der Wasserspiegellage / Auswahlunterstützung)
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Wed Sep 28 14:03:31 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu Sep 29 09:14:41 2011 +0000
@@ -1336,39 +1336,8 @@
      * @return a double array with [min, max].
      */
     protected double[] getMinMaxKM(DataList[] data) {
-        int     num = data != null ? data.length : 0;
-        double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
-
-        for (int i = 0; i < num; i++) {
-            DataList dl = data[i];
-
-            if (dl.getState().equals("state.winfo.location_distance")) {
-                for (int j = 0, n = dl.size(); j < n; j++) {
-                    Data d = dl.get(j);
-
-                    String label = d.getLabel();
-                    if (label.equals("ld_step") || label.equals("ld_mode")) {
-                        continue;
-                    }
-
-                    for (DataItem item: d.getItems()) {
-                        String itemValue = item.getStringValue();
-
-                        try {
-                            double v = Double.valueOf(itemValue);
-
-                            mm[0] = mm[0] < v ? mm[0] : v;
-                            mm[1] = mm[1] > v ? mm[1] : v;
-                        }
-                        catch (NumberFormatException nfe) {
-                            // do nothing
-                        }
-                    }
-                }
-            }
-        }
-
-        return mm;
+        ArtifactDescription adesc = artifact.getArtifactDescription();
+        return adesc.getKMRange();
     }
 
 
@@ -1380,24 +1349,8 @@
      * @return the name of the current river.
      */
     protected String getRiverName(DataList[] data) {
-        if (data != null && data.length > 0) {
-            for (int i = 0; i < data.length; i++) {
-                DataList dl = data[i];
-
-                if (dl.getState().equals("state.winfo.river")) {
-                    for (int j = 0; j < dl.size(); j++) {
-                        Data d = dl.get(j);
-                        DataItem[] di = d.getItems();
-
-                        if (di != null && di.length == 1) {
-                           return d.getItems()[0].getStringValue();
-                        }
-                    }
-                }
-            }
-        }
-
-        return null;
+        ArtifactDescription adesc = artifact.getArtifactDescription();
+        return adesc.getRiver();
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java	Thu Sep 29 09:14:41 2011 +0000
@@ -0,0 +1,54 @@
+package de.intevation.flys.client.shared;
+
+
+public final class DoubleUtils {
+
+    public static final String DEFAULT_DELIM = " ";
+
+
+    private DoubleUtils() {
+    }
+
+
+    public static Double getDouble(String value) {
+        try {
+            return Double.valueOf(value);
+        }
+        catch (NumberFormatException nfe) {
+            // do nothing
+        }
+
+        return null;
+    }
+
+
+    public static double[] getMinMax(String value) {
+        return getMinMax(value, DEFAULT_DELIM);
+    }
+
+
+    public static double[] getMinMax(String value, String delim) {
+        if (value == null) {
+            return null;
+        }
+
+        String[] values = value.split(delim);
+
+        int     len = values != null ? values.length : 0;
+        double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
+
+        for (int i = 0; i < len; i++) {
+            Double d = getDouble(values[i]);
+
+            if (d != null) {
+                mm[0] = mm[0] < d ? mm[0] : d;
+                mm[1] = mm[1] > d ? mm[1] : d;
+            }
+        }
+
+        return mm[0] != Double.MAX_VALUE && mm[1] != -Double.MAX_VALUE
+            ? mm
+            : null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java	Wed Sep 28 14:03:31 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ArtifactDescription.java	Thu Sep 29 09:14:41 2011 +0000
@@ -47,6 +47,22 @@
 
 
     /**
+     * Returns the name of the selected river.
+     *
+     * @return the selected river.
+     */
+    public String getRiver();
+
+
+    /**
+     * Returns the selected min and max kilomter if existing otherwise null.
+     *
+     * @return an array of [min-km, max-km] if existing otherwise null.
+     */
+    public double[] getKMRange();
+
+
+    /**
      * Returns the available output modes.
      *
      * @return the available output modes.
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultArtifactDescription.java	Wed Sep 28 14:03:31 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultArtifactDescription.java	Thu Sep 29 09:14:41 2011 +0000
@@ -1,5 +1,9 @@
 package de.intevation.flys.client.shared.model;
 
+import java.util.List;
+
+import de.intevation.flys.client.shared.DoubleUtils;
+
 
 /**
  * The default implementation of an {@link ArtifactDescription}. This class just
@@ -105,5 +109,61 @@
     public Recommendation[] getRecommendations() {
         return recommendations;
     }
+
+
+    public String getRiver() {
+        for (DataList list: oldData) {
+            List<Data> dataList = list.getAll();
+
+            for (Data d: dataList) {
+                String dataName = d.getLabel();
+                DataItem item   = d.getItems()[0];
+
+                if (dataName.equals("river")) {
+                    return item.getStringValue();
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+    public double[] getKMRange() {
+        Double[] mm = new Double[2];
+
+        for (DataList list: oldData) {
+            List<Data> dataList = list.getAll();
+
+            for (Data data: dataList) {
+                String dataName = data.getLabel();
+                DataItem item   = data.getItems()[0];
+
+                if (dataName.equals("ld_from")) {
+                    Double d = DoubleUtils.getDouble(item.getStringValue());
+
+                    if (d != null) {
+                        mm[0] = d;
+                    }
+                }
+                else if (dataName.equals("ld_to")) {
+                    Double d = DoubleUtils.getDouble(item.getStringValue());
+
+                    if (d != null) {
+                        mm[1] = d;
+                    }
+                }
+                else if (dataName.equals("ld_locations")) {
+                    return DoubleUtils.getMinMax(item.getStringValue());
+                }
+            }
+
+            if (mm[0] != null && mm[1] != null) {
+                return new double[] { mm[0], mm[1] };
+            }
+        }
+
+        return null;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org