Mercurial > dive4elements > river
changeset 5123:64766b89beb6
WQAdaptedInputPanel: Refactored to remove code dupes.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 27 Feb 2013 12:19:41 +0100 |
parents | 15ff9ddc765e |
children | 17f4cd1acc96 |
files | flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java |
diffstat | 1 files changed, 7 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- 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> 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]; + protected List<String> 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<String> validateQ() { + return validateRange(qranges); }