# HG changeset patch # User Sascha L. Teichmann # Date 1320314284 0 # Node ID e3eb1ea885a71b8f916af323f114fede09b10dda # Parent 595c404523a69c62d7a5672aa622b0c3aa821e69 Simplified code in Datacage builder by using the new pair. flys-artifacts/trunk@3147 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 595c404523a6 -r e3eb1ea885a7 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Nov 03 09:47:52 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Nov 03 09:58:04 2011 +0000 @@ -1,3 +1,10 @@ +2011-11-03 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java: + Use new pair in stack of results and connections because they are + always used in pairs. Maintaining two separate stacks is not + needed any longer. + 2011-11-03 Sascha L. Teichmann * src/main/java/de/intevation/flys/utils/Pair.java: New. A generic pair. diff -r 595c404523a6 -r e3eb1ea885a7 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Thu Nov 03 09:47:52 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java Thu Nov 03 09:58:04 2011 +0000 @@ -26,6 +26,8 @@ import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.utils.Pair; + import org.apache.log4j.Logger; public class Builder @@ -82,13 +84,12 @@ public class BuildHelper { - protected Node output; - protected Document owner; - protected StackFrames frames; - protected List connections; - protected Map statements; - protected Deque connectionsStack; - protected Deque resultsStack; + protected Node output; + protected Document owner; + protected StackFrames frames; + protected List connections; + protected Map statements; + protected Deque> connectionsStack; public BuildHelper( Node output, @@ -100,8 +101,8 @@ } this.connections = connections; - connectionsStack = new ArrayDeque(); - resultsStack = new ArrayDeque(); + connectionsStack = + new ArrayDeque>(); this.output = output; frames = new StackFrames(parameters); owner = getOwnerDocument(output); @@ -172,7 +173,7 @@ NamedConnection connection = connectionsStack.isEmpty() ? connections.get(0) - : connectionsStack.peek(); + : connectionsStack.peek().getA(); if (con.length() > 0) { for (NamedConnection nc: connections) { @@ -190,8 +191,7 @@ // only descent if there are results if (!rd.isEmpty()) { - resultsStack.push(rd); - connectionsStack.push(connection); + connectionsStack.push(new Pair(connection, rd)); try { for (int i = 0; i < S; ++i) { build(parent, subs.item(i)); @@ -199,7 +199,6 @@ } finally { connectionsStack.pop(); - resultsStack.pop(); } } } @@ -209,7 +208,7 @@ { log.debug("dc:elements"); - if (resultsStack.isEmpty()) { + if (connectionsStack.isEmpty()) { log.warn("dc:elements without having results"); return; } @@ -222,7 +221,7 @@ return; } - ResultData rd = resultsStack.peek(); + ResultData rd = connectionsStack.peek().getB(); String [] columns = rd.getColumnLabels();