# HG changeset patch # User Sascha L. Teichmann # Date 1347119888 0 # Node ID fe29b0226faff8bd82cdbfe4c32a5eeeaf7d4dcc # Parent e32b822f3cfae1f1e79c0a889f1da65f6f6117d5 More iterator code simplification. flys-artifacts/trunk@5405 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e32b822f3cfa -r fe29b0226faf flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/themes/DefaultThemeField.java: diff -r e32b822f3cfa -r fe29b0226faf flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.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 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 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); diff -r e32b822f3cfa -r fe29b0226faf flys-artifacts/src/main/java/de/intevation/flys/themes/DefaultTheme.java --- 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 iter = attr.keySet().iterator(); - while (iter.hasNext()) { - String key = iter.next(); - String val = getAttribute(key); + for (Map.Entry 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 iter = fields.keySet().iterator(); - while (iter.hasNext()) { - String name = iter.next(); - - ThemeField field = getField(name); + for (Map.Entry entry: fields.entrySet()) { + String name = entry.getKey(); + ThemeField field = entry.getValue(); Document doc = field.toXML(); Node root = doc.getFirstChild();