# HG changeset patch # User Bjoern Ricks # Date 1348227268 0 # Node ID cf64f54aa39c67bd73b1fd60b6b611ec7fb4eaea # Parent 509ef6ec93af19d8f73350dbe404523cfcf6ffb8 Refactor to avoid code duplication flys-client/trunk@5555 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 509ef6ec93af -r cf64f54aa39c flys-client/ChangeLog --- a/flys-client/ChangeLog Fri Sep 21 11:08:34 2012 +0000 +++ b/flys-client/ChangeLog Fri Sep 21 11:34:28 2012 +0000 @@ -1,3 +1,8 @@ +2012-09-21 Björn Ricks + + * src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java: + Refactor to avoid code duplication + 2012-09-21 Björn Ricks * src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, diff -r 509ef6ec93af -r cf64f54aa39c flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java Fri Sep 21 11:08:34 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java Fri Sep 21 11:34:28 2012 +0000 @@ -238,16 +238,13 @@ String label = d.getLabel(); GWT.log("GaugeTree - setData - label " + label + " " + d.getStringValue()); if (label.equals("ld_from")) { - String strfrom = d.getStringValue(); - if (strfrom != null) { - ldfrom = Double.valueOf(strfrom); - } + ldfrom = getDoubleValue(d); } else if (label.equals("ld_to")) { - String strto = d.getStringValue(); - if (strto != null) { - ldto = Double.valueOf(strto); - } + ldto = getDoubleValue(d); + } + else if (label.equals("ld_mode")) { + GWT.log("GaugeTree - setData - ld_mode " + d.getStringValue()); } } @@ -264,16 +261,7 @@ GWT.log("GaugeTree - setData - location label " + label + " " + d.getStringValue()); if (label.equals("ld_locations")) { - DataItem[] items = d.getItems(); - for (int k = 0; k < items.length; k++) { - String tmp = items[k].getStringValue(); - if (tmp != null) { - Double value = Double.valueOf(tmp); - if (value != null) { - locations.add(value); - } - } - } + getLocations(locations, d.getItems()); } } openOnLocations(locations); @@ -284,16 +272,7 @@ Data d = dl.get(j); String label = d.getLabel(); if (label.equals("reference_startpoint")) { - DataItem[] items = d.getItems(); - for (int k = 0; k < items.length; k++) { - String tmp = items[k].getStringValue(); - if (tmp != null) { - Double value = Double.valueOf(tmp); - if (value != null) { - curvelocations.add(value); - } - } - } + getLocations(curvelocations, d.getItems()); } } } @@ -302,16 +281,7 @@ Data d = dl.get(j); String label = d.getLabel(); if (label.equals("reference_endpoint")) { - DataItem[] items = d.getItems(); - for (int k = 0; k < items.length; k++) { - String tmp = items[k].getStringValue(); - if (tmp != null) { - Double value = Double.valueOf(tmp); - if (value != null) { - curvelocations.add(value); - } - } - } + getLocations(curvelocations, d.getItems()); } } } @@ -339,6 +309,25 @@ } } + private void getLocations(List locations, DataItem[] items) { + for (int k = 0; k < items.length; k++) { + String tmp = items[k].getStringValue(); + if (tmp != null) { + Double value = Double.valueOf(tmp); + if (value != null) { + locations.add(value); + } + } + } + } + private Double getDoubleValue(Data d) { + String tmp = d.getStringValue(); + if (tmp != null) { + return Double.valueOf(tmp); + } + return null; + } + public void openOnDistance(Double start, Double end) { GWT.log("GaugeTree - openOnDistance " + start + " " + end + " " + tree.getItemCount());