changeset 3732:fe29b0226faf

More iterator code simplification. flys-artifacts/trunk@5405 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 08 Sep 2012 15:58:08 +0000
parents e32b822f3cfa
children 893b2477208f
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java flys-artifacts/src/main/java/de/intevation/flys/themes/DefaultTheme.java
diffstat 3 files changed, 30 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sat Sep 08 15:27:21 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sat Sep 08 15:58:08 2012 +0000
@@ -1,3 +1,9 @@
+2012-09-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/DefaultState.java,
+	  src/main/java/de/intevation/flys/themes/DefaultTheme.java:
+	  More iterator code simplification.
+
 2012-09-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/themes/DefaultThemeField.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Sat Sep 08 15:27:21 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Sat Sep 08 15:58:08 2012 +0000
@@ -1,7 +1,6 @@
 package de.intevation.flys.artifacts.states;
 
 import java.text.NumberFormat;
-import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
 import java.util.List;
@@ -87,11 +86,9 @@
             return ui;
         }
 
-        Iterator<String> iter = theData.keySet().iterator();
-        FLYSArtifact     flys = (FLYSArtifact) artifact;
+        FLYSArtifact flys = (FLYSArtifact)artifact;
 
-        while (iter.hasNext()) {
-            String name = iter.next();
+        for (String name: theData.keySet()) {
             appendStaticData(flys, context, creator, ui, name);
         }
 
@@ -115,9 +112,11 @@
 
         String type = data.getType();
 
-        logger.debug(
-            "Append element " + type + "'" +
-            name + "' (" + value + ")");
+        if (logger.isDebugEnabled()) {
+            logger.debug(
+                "Append element " + type + "'" +
+                name + "' (" + value + ")");
+        }
 
         Element e = createStaticData(flys, cr, context, name, value, type);
 
@@ -183,7 +182,7 @@
         try {
             // XXX A better way to format the output would be to use the
             // 'type' value of the data objects.
-            double doubleVal = Double.valueOf(value);
+            double doubleVal = Double.parseDouble(value);
             Locale         l = Resources.getLocale(meta);
             NumberFormat  nf = NumberFormat.getInstance(l);
 
@@ -259,14 +258,14 @@
             return ui;
         }
 
-        Iterator<String> iter = theData.keySet().iterator();
-        FLYSArtifact     flys = (FLYSArtifact) artifact;
+        FLYSArtifact flys = (FLYSArtifact)artifact;
 
-        while (iter.hasNext()) {
-            String    name = iter.next();
+        for (String name: theData.keySet()) {
             StateData data = getData(flys, name);
 
-            data = data != null ? data : getData(name);
+            if (data == null) {
+                data = getData(name);
+            }
 
             Element select = createData(creator, artifact, data, context);
 
@@ -407,7 +406,9 @@
         String       name,
         String       val
     ) {
-        logger.debug("Transform data ('" + name + "','" + val + "')");
+        if (logger.isDebugEnabled()) {
+            logger.debug("Transform data ('" + name + "','" + val + "')");
+        }
 
         stateData.setValue(val);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/themes/DefaultTheme.java	Sat Sep 08 15:27:21 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/DefaultTheme.java	Sat Sep 08 15:58:08 2012 +0000
@@ -1,7 +1,6 @@
 package de.intevation.flys.themes;
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.w3c.dom.Document;
@@ -154,17 +153,14 @@
      * @param theme The document root element.
      */
     protected void appendAttributes(ElementCreator cr, Element theme) {
-        Iterator<String> iter = attr.keySet().iterator();
 
-        while (iter.hasNext()) {
-            String key = iter.next();
-            String val = getAttribute(key);
+        for (Map.Entry<String, String> entry: attr.entrySet()) {
+            String key = entry.getKey();
+            String val = entry.getValue();
 
-            if (key == null || val == null) {
-                continue;
+            if (key != null && val != null) {
+                cr.addAttr(theme, key, val);
             }
-
-            cr.addAttr(theme, key, val);
         }
     }
 
@@ -176,12 +172,10 @@
      * @param theme The document root element.
      */
     protected void appendFields(ElementCreator cr, Element theme) {
-        Iterator<String> iter = fields.keySet().iterator();
 
-        while (iter.hasNext()) {
-            String name = iter.next();
-
-            ThemeField field = getField(name);
+        for (Map.Entry<String, ThemeField> entry: fields.entrySet()) {
+            String     name  = entry.getKey();
+            ThemeField field = entry.getValue();
 
             Document doc = field.toXML();
             Node    root = doc.getFirstChild();

http://dive4elements.wald.intevation.org