# HG changeset patch # User Felix Wolfsteller # 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 validateW() { + protected List validateRange(Map ranges) { List errors = new ArrayList(); 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 validateQ() { - List errors = new ArrayList(); - NumberFormat nf = NumberFormat.getDecimalFormat(); - - Iterator iter = wqranges.keySet().iterator(); - - while (iter.hasNext()) { - List tmpErrors = new ArrayList(); - - 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]; + protected List validateW() { + return validateRange(wranges); + } - 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; + protected List validateQ() { + return validateRange(qranges); }