[PATCH] Client: Removed an XPath eval and simplified a loop
Wald Commits
scm-commit at wald.intevation.org
Mon Aug 19 16:02:53 CEST 2013
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1376920968 -7200
# Node ID 0f3dad5d74a2a5013b11bcc43afcdbb883e4998a
# Parent 93c0a1692aa56d279220e10e9176930b0794c690
Client: Removed an XPath eval and simplified a loop.
diff -r 93c0a1692aa5 -r 0f3dad5d74a2 gwt-client/src/main/java/org/dive4elements/river/client/server/FixingsOverviewServiceImpl.java
--- 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;
diff -r 93c0a1692aa5 -r 0f3dad5d74a2 gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixingsOverviewInfo.java
--- 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;
More information about the Dive4elements-commits
mailing list