From: "Enrico Weigelt, metux IT consult" <enrico.weig...@gr13.net>

---
 .../freecol/client/control/InGameInputHandler.java | 25 +++++++++------
 .../common/networking/AddPlayerMessage.java        | 11 +++++--
 .../freecol/common/networking/MultipleMessage.java | 12 ++++++--
 .../common/networking/ServerListMessage.java       | 11 +++++--
 .../freecol/common/networking/UpdateMessage.java   |  8 +++--
 src/net/sf/freecol/common/util/DOMUtils.java       | 36 ----------------------
 6 files changed, 47 insertions(+), 56 deletions(-)

diff --git a/src/net/sf/freecol/client/control/InGameInputHandler.java 
b/src/net/sf/freecol/client/control/InGameInputHandler.java
index dcb8af1439e..1aa5f04a55a 100644
--- a/src/net/sf/freecol/client/control/InGameInputHandler.java
+++ b/src/net/sf/freecol/client/control/InGameInputHandler.java
@@ -438,9 +438,13 @@ public final class InGameInputHandler extends 
ClientInputHandler {
             return;
         }
 
-        DOMUtils.mapChildren(element, (e) -> {
-                final String tag = DOMUtils.getType(e);
-                switch (tag) {
+        NodeList nodes = element.getChildNodes();
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Element e = (Element)nodes.item(i);
+            if (e == null) continue;
+
+            final String tag = DOMUtils.getType(e);
+            switch (tag) {
                 case Ability.TAG:
                     Ability a = new Ability(spec);
                     DOMUtils.readFromXMLElement(a, e);
@@ -515,9 +519,8 @@ public final class InGameInputHandler extends 
ClientInputHandler {
                 default:
                     logger.warning("featureChange unrecognized: " + tag);
                     break;
-                }
-                return null;
-            });
+            }
+        }
     }
 
     /**
@@ -844,7 +847,10 @@ public final class InGameInputHandler extends 
ClientInputHandler {
             = game.getFreeColGameObject(element.getAttribute("divert"));
         final List<FreeColGameObject> objects = new ArrayList<>();
 
-        DOMUtils.mapChildren(element, (e) -> {
+        NodeList nodes = element.getChildNodes();
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Element e = (Element)nodes.item(i);
+            if (e != null) {
                 final String id = DOMUtils.readId(e);
                 FreeColGameObject fcgo = game.getFreeColGameObject(id);
                 if (fcgo != null) {
@@ -855,8 +861,9 @@ public final class InGameInputHandler extends 
ClientInputHandler {
                     // remove is processed.
                     objects.add(fcgo);
                 }
-                return fcgo;
-            });
+            }
+        };
+
         if (!objects.isEmpty()) {
             invokeLater(() -> igc().remove(objects, divert));
         }
diff --git a/src/net/sf/freecol/common/networking/AddPlayerMessage.java 
b/src/net/sf/freecol/common/networking/AddPlayerMessage.java
index b7f7dc7fc68..3a619f6159c 100644
--- a/src/net/sf/freecol/common/networking/AddPlayerMessage.java
+++ b/src/net/sf/freecol/common/networking/AddPlayerMessage.java
@@ -29,6 +29,7 @@ import net.sf.freecol.server.model.ServerPlayer;
 
 import net.sf.freecol.common.util.DOMUtils;
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 
 /**
@@ -67,8 +68,14 @@ public class AddPlayerMessage extends DOMMessage {
         // Making this message implicitly updates the game.
         // TODO: should this do a non-interning read and have the client
         // handlers do more checking?
-        this.players.addAll(DOMUtils.mapChildren(element, (e) ->
-                DOMUtils.readGameElement(game, e, true, Player.class)));
+        NodeList nodes = element.getChildNodes();
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Element e = (Element)nodes.item(i);
+            if (e == null) continue;
+
+            Player p = DOMUtils.readGameElement(game, e, true, Player.class);
+            if (p != null) this.players.add(p);
+        }
     }
 
 
diff --git a/src/net/sf/freecol/common/networking/MultipleMessage.java 
b/src/net/sf/freecol/common/networking/MultipleMessage.java
index 51b61bf3991..ccd85c1a6c5 100644
--- a/src/net/sf/freecol/common/networking/MultipleMessage.java
+++ b/src/net/sf/freecol/common/networking/MultipleMessage.java
@@ -21,7 +21,6 @@ package net.sf.freecol.common.networking;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.function.Function;
 
 import net.sf.freecol.common.model.Game;
 import net.sf.freecol.common.model.Player;
@@ -29,6 +28,7 @@ import net.sf.freecol.server.FreeColServer;
 
 import net.sf.freecol.common.util.DOMUtils;
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 
 /**
@@ -60,7 +60,11 @@ public class MultipleMessage extends DOMMessage {
      * @param element An element containing the sub-{@code Element}s.
      */
     public MultipleMessage(Element element) {
-        this(DOMUtils.mapChildren(element, Function.identity()));
+        super(TAG);
+
+        NodeList nodes = element.getChildNodes();
+        for (int i = 0; i < nodes.getLength(); i++)
+            this.elements.add((Element)nodes.item(i));
     }
 
     /**
@@ -73,7 +77,9 @@ public class MultipleMessage extends DOMMessage {
     public MultipleMessage(Game game, Element element) {
         this((List<Element>)null);
 
-        this.elements.addAll(DOMUtils.mapChildren(element, 
Function.identity()));
+        NodeList nodes = element.getChildNodes();
+        for (int i = 0; i < nodes.getLength(); i++)
+            this.elements.add((Element)nodes.item(i));
     }
 
 
diff --git a/src/net/sf/freecol/common/networking/ServerListMessage.java 
b/src/net/sf/freecol/common/networking/ServerListMessage.java
index 82dc999fdc5..84fe010a70d 100644
--- a/src/net/sf/freecol/common/networking/ServerListMessage.java
+++ b/src/net/sf/freecol/common/networking/ServerListMessage.java
@@ -30,6 +30,7 @@ import net.sf.freecol.server.FreeColServer;
 
 import net.sf.freecol.common.util.DOMUtils;
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 
 /**
@@ -62,9 +63,13 @@ public class ServerListMessage extends DOMMessage {
      */
     public ServerListMessage(Game game, Element element) {
         this();
-
-        this.servers.addAll(DOMUtils.mapChildren(element,
-                e -> new RegisterServerMessage(null, 
element).getServerInfo()));
+        NodeList nodes = element.getChildNodes();
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Element e = (Element)nodes.item(i);
+            if (e == null) continue;
+            ServerInfo si = new RegisterServerMessage(null, 
element).getServerInfo();
+            if (si != null) this.servers.add(si);
+        }
     }
 
 
diff --git a/src/net/sf/freecol/common/networking/UpdateMessage.java 
b/src/net/sf/freecol/common/networking/UpdateMessage.java
index 517373de15b..5af79b2a30a 100644
--- a/src/net/sf/freecol/common/networking/UpdateMessage.java
+++ b/src/net/sf/freecol/common/networking/UpdateMessage.java
@@ -30,6 +30,7 @@ import net.sf.freecol.server.model.ServerPlayer;
 
 import net.sf.freecol.common.util.DOMUtils;
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 
 /**
@@ -64,9 +65,10 @@ public class UpdateMessage extends DOMMessage {
      */
     public UpdateMessage(Game game, Element element) {
         this(null);
-
-        for (FreeColGameObject f : DOMUtils.mapChildren(element, (e) ->
-                DOMUtils.updateFromElement(game, e))) {
+        NodeList nodes = element.getChildNodes();
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Element e = (Element)nodes.item(i);
+            FreeColGameObject f = DOMUtils.updateFromElement(game, e);
             if (f != null) this.fcgos.add(f);
         }
     }
diff --git a/src/net/sf/freecol/common/util/DOMUtils.java 
b/src/net/sf/freecol/common/util/DOMUtils.java
index f811fb9d2f8..8e7b8d773e6 100644
--- a/src/net/sf/freecol/common/util/DOMUtils.java
+++ b/src/net/sf/freecol/common/util/DOMUtils.java
@@ -25,7 +25,6 @@ import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.ArrayList;
-import java.util.function.Function;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -228,20 +227,6 @@ public class DOMUtils {
     }
 
     /**
-     * Handle the child nodes of an element.
-     *
-     * @param mh The {@code MessageHandler} to handle the nodes.
-     * @param connection The {@code Connection} the element arrived on.
-     * @param element The {@code Element} to process.
-     * @return An {@code Element} containing the response/s.
-     */
-    public static final Element handleChildren(MessageHandler mh,
-        Connection connection, Element element) {
-        return handleList(mh, connection,
-                          mapChildren(element, Function.identity()));
-    }
-
-    /**
      * Handle a list of messages.
      *
      * @param mh The {@code MessageHandler} to handle the messages.
@@ -350,27 +335,6 @@ public class DOMUtils {
     }
 
     /**
-     * Convenience method to map a function over the children of an Element.
-     *
-     * @param <T> The actual list member return type.
-     * @param element The {@code Element} to extract children from.
-     * @param mapper A mapper function.
-     * @return A list of results of the mapping.
-     */
-    public static <T> List<T> mapChildren(Element element,
-        Function<? super Element, ? extends T> mapper) {
-        List<T> ret = new ArrayList<>();
-        NodeList nl = element.getChildNodes();
-        for (int i = 0; i < nl.getLength(); i++) {
-            Element e = (Element)nl.item(i);
-            if (e == null) continue;
-            T x = mapper.apply((Element)nl.item(i));
-            if (x != null) ret.add(x);
-        }
-        return ret;
-    }
-
-    /**
      * Get all the attributes of an element as a map.
      *
      * @param element The {@code Element} to query.
-- 
2.11.0.rc0.7.gbe5a750


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to