changeset 3840:cf64f54aa39c

Refactor to avoid code duplication flys-client/trunk@5555 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 21 Sep 2012 11:34:28 +0000
parents 509ef6ec93af
children 5877d6900e34
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java
diffstat 2 files changed, 32 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- 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	<bjoern.ricks@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java:
+	  Refactor to avoid code duplication
+
 2012-09-21	Björn Ricks	<bjoern.ricks@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
--- 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<Double> 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());

http://dive4elements.wald.intevation.org