[Dive4elements-commits] [PATCH 1 of 2] WQAdaptedInputPanel: Refactored to remove code dupes

Wald Commits scm-commit at wald.intevation.org
Thu Feb 28 10:14:51 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1361963981 -3600
# Node ID 64766b89beb6a006e598995e3fda514ed5ff3940
# Parent  15ff9ddc765ef3ca7dc5da936d180d96f2db1e4a
WQAdaptedInputPanel: Refactored to remove code dupes.

diff -r 15ff9ddc765e -r 64766b89beb6 flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Wed Feb 27 17:12:56 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Wed Feb 27 12:19:41 2013 +0100
@@ -268,8 +268,7 @@
         }
     }
 
-
-    protected List<String> validateW() {
+    protected List<String> validateRange(Map<String, double[]> ranges) {
         List<String> errors = new ArrayList<String>();
         NumberFormat nf     = NumberFormat.getDecimalFormat();
 
@@ -286,7 +285,7 @@
                 return errors;
             }
 
-            double[] mm  = wranges.get(key);
+            double[] mm  = ranges.get(key);
             if (mm == null) {
                 SC.warn(MSG.error_read_minmax_values());
                 continue;
@@ -326,60 +325,13 @@
     }
 
 
+    protected List<String> validateW() {
+        return validateRange(wranges);
+    }
+
+
     protected List<String> validateQ() {
-        List<String> errors = new ArrayList<String>();
-        NumberFormat nf     = NumberFormat.getDecimalFormat();
-
-        Iterator<String> iter = wqranges.keySet().iterator();
-
-        while (iter.hasNext()) {
-            List<String> tmpErrors = new ArrayList<String>();
-
-            String           key = iter.next();
-            DoubleArrayPanel dap = wqranges.get(key);
-
-            if (!dap.validateForm()) {
-                errors.add(MSG.error_invalid_double_value());
-                return errors;
-            }
-
-            double[] mm = qranges.get(key);
-            if (mm == null) {
-                SC.warn(MSG.error_read_minmax_values());
-                continue;
-            }
-
-            double[] values = dap.getInputValues();
-            double[] good   = new double[values.length];
-
-            int idx = 0;
-
-            for (double value: values) {
-                if (value < mm[0] || value > mm[1]) {
-                    String tmp = MSG.error_validate_range();
-                    tmp = tmp.replace("$1", nf.format(value));
-                    tmp = tmp.replace("$2", nf.format(mm[0]));
-                    tmp = tmp.replace("$3", nf.format(mm[1]));
-                    tmpErrors.add(tmp);
-                }
-                else {
-                    good[idx++] = value;
-                }
-            }
-
-            double[] justGood = new double[idx];
-            for (int i = 0; i < justGood.length; i++) {
-                justGood[i] = good[i];
-            }
-
-            if (!tmpErrors.isEmpty()) {
-                dap.setValues(justGood);
-
-                errors.addAll(tmpErrors);
-            }
-        }
-
-        return errors;
+        return validateRange(qranges);
     }
 
 


More information about the Dive4elements-commits mailing list