|
Author: adrianc
Date: Tue Jan 12 15:32:29 2010 New Revision: 898369 URL: http://svn.apache.org/viewvc?rev=898369&view=rev Log: Minor code improvements. Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java?rev=898369&r1=898368&r2=898369&view=diff ============================================================================== --- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java (original) +++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java Tue Jan 12 15:32:29 2010 @@ -39,18 +39,26 @@ public ArtifactPath(String artifactPath) { this.pathElementArray = artifactPath.split(AbstractExecutionContext.PATH_ELEMENT_SEPARATOR); } - + public ArtifactPath(String[] pathElementArray) { this.pathElementArray = pathElementArray; } - + public String getCurrentPath() { if (this.pathElementArray.length == 1 || !this.hasNext()) { return this.pathElementArray[this.currentIndex]; } + return getPathAsString(this.currentIndex); + } + + public String getCurrentPathElement() { + return this.pathElementArray[this.currentIndex]; + } + + protected String getPathAsString(int index) { this.stringBuilder.clear(); - for (int i = this.currentIndex; i < this.pathElementArray.length; i++) { - if (i != this.currentIndex) { + for (int i = index; i < this.pathElementArray.length; i++) { + if (i != index) { stringBuilder.append(AbstractExecutionContext.PATH_ELEMENT_SEPARATOR); } stringBuilder.append(this.pathElementArray[i]); @@ -58,10 +66,6 @@ return stringBuilder.toString(); } - public String getCurrentPathElement() { - return this.pathElementArray[this.currentIndex]; - } - @Override public boolean hasNext() { return this.currentIndex + 1 < this.pathElementArray.length; @@ -80,6 +84,12 @@ throw new UnsupportedOperationException(); } + public void restoreState() { + if (this.stack != null && !this.stack.isEmpty()) { + this.currentIndex = this.stack.removeLast(); + } + } + public void saveState() { if (this.stack == null) { this.stack = FastList.newInstance(); @@ -87,9 +97,8 @@ this.stack.addLast(this.currentIndex); } - public void restoreState() { - if (this.stack != null && !this.stack.isEmpty()) { - this.currentIndex = this.stack.removeLast(); - } + @Override + public String toString() { + return getPathAsString(0); } } Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java?rev=898369&r1=898368&r2=898369&view=diff ============================================================================== --- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java (original) +++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java Tue Jan 12 15:32:29 2010 @@ -36,7 +36,7 @@ this.node = node; } - protected void buildNodeString(PathNode node) { + protected void buildChildNodeString(PathNode node) { if (node.childNodes != null) { Collection<PathNode> childNodes = node.childNodes.values(); for (PathNode childNode : childNodes) { @@ -63,27 +63,27 @@ this.stringBuilder.append(node.permission); this.stringBuilder.append("]\n"); } - if (node.substitutionNode != null) { - node.substitutionNode.accept(this); - } if (node.wildCardNode != null) { node.wildCardNode.accept(this); } - this.buildNodeString(node); + if (node.substitutionNode != null) { + node.substitutionNode.accept(this); + } + this.buildChildNodeString(node); this.currentPath.removeLast(); } @Override public void visit(SubstitutionNode node) { this.currentPath.addLast(node); - this.buildNodeString(node); + this.buildChildNodeString(node); this.currentPath.removeLast(); } @Override public void visit(WildCardNode node) { this.currentPath.addLast(node); - this.buildNodeString(node); + this.buildChildNodeString(node); this.currentPath.removeLast(); } Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java?rev=898369&r1=898368&r2=898369&view=diff ============================================================================== --- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java (original) +++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java Tue Jan 12 15:32:29 2010 @@ -34,14 +34,14 @@ public void visit(BranchNode node) { if (this.artifactPath.hasNext()) { String key = this.artifactPath.next(); - if (node.substitutionNode != null) { + if (node.wildCardNode != null) { this.artifactPath.saveState(); - node.substitutionNode.accept(this); + node.wildCardNode.accept(this); this.artifactPath.restoreState(); } - if (node.wildCardNode != null) { + if (node.substitutionNode != null) { this.artifactPath.saveState(); - node.wildCardNode.accept(this); + node.substitutionNode.accept(this); this.artifactPath.restoreState(); } this.visitChildNode(node, key); |
| Free forum by Nabble | Edit this page |
