changeset 6867:0f3dad5d74a2

Client: Removed an XPath eval and simplified a loop.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 19 Aug 2013 16:02:48 +0200
parents 93c0a1692aa5
children 08e3c22500f3
files gwt-client/src/main/java/org/dive4elements/river/client/server/FixingsOverviewServiceImpl.java gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixingsOverviewInfo.java
diffstat 2 files changed, 13 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/FixingsOverviewServiceImpl.java	Mon Aug 19 12:48:03 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/FixingsOverviewServiceImpl.java	Mon Aug 19 16:02:48 2013 +0200
@@ -33,8 +33,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.xml.xpath.XPathConstants;
-
 import org.apache.log4j.Logger;
 
 import org.w3c.dom.Document;
@@ -58,9 +56,6 @@
     protected static final String XPATH_RFROM = "/fixings/river/@from";
     protected static final String XPATH_RTO = "/fixings/river/@to";
 
-    protected static final String XPATH_EVENT = "/fixings/events/event";
-
-
     @Override
     public FixingsOverviewInfo generateOverview(
         String  locale,
@@ -193,18 +188,16 @@
     protected List<FixEvent> getFixEvents(Document doc) {
         List<FixEvent> list = new ArrayList<FixEvent>();
 
-        NodeList events = (NodeList) XMLUtils.xpath(
-            doc,
-            XPATH_EVENT,
-            XPathConstants.NODESET,
-            null);
+        NodeList events = doc.getElementsByTagName("event");
 
-        if (events == null || events.getLength() == 0) {
+        int E = events.getLength();
+
+        if (E == 0) {
             log.warn("No events in Overview!");
             return list;
         }
 
-        for (int i = 0, E = events.getLength(); i < E; i++) {
+        for (int i = 0; i < E; i++) {
             Element n = (Element)events.item(i);
             List<Sector> sectors = getSectors(n);
             String cid  = n.getAttribute("cid");
@@ -218,13 +211,15 @@
     protected List<Sector> getSectors(Element event) {
         NodeList sectors = event.getElementsByTagName("sector");
 
-        if (sectors.getLength() == 0) {
+        int S = sectors.getLength();
+
+        if (S == 0) {
             log.warn("No Sectors in Event!");
             return null;
         }
 
-        List<Sector> list = new ArrayList<Sector>();
-        for (int i = 0, S = sectors.getLength(); i < S; i++) {
+        List<Sector> list = new ArrayList<Sector>(S);
+        for (int i = 0; i < S; i++) {
             Element n = (Element)sectors.item(i);
             int    cls  = -1;
             double from = -1;
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixingsOverviewInfo.java	Mon Aug 19 12:48:03 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixingsOverviewInfo.java	Mon Aug 19 16:02:48 2013 +0200
@@ -61,9 +61,9 @@
     }
 
     public FixEvent getEventByCId(String cid) {
-        for (int i = 0; i < events.size(); i++) {
-            if (events.get(i).getCId().equals(cid)) {
-                return events.get(i);
+        for (FixEvent event: events) {
+            if (event.getCId().equals(cid)) {
+                return event;
             }
         }
         return null;

http://dive4elements.wald.intevation.org