Mercurial > hg > Members > shoshi > TreeCMS > TreeCMSPrototype1
changeset 18:423a01ec2d32
findPath and cloneTree in PreorderTreewalker1 (not yet tested)
author | one |
---|---|
date | Mon, 30 Aug 2010 00:48:50 +0900 |
parents | cc89a4664927 |
children | a281fb7eaf39 |
files | src/treecms/proto/test/PreOrderTreeWalker.java |
diffstat | 1 files changed, 5 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/treecms/proto/test/PreOrderTreeWalker.java Mon Aug 30 00:05:44 2010 +0900 +++ b/src/treecms/proto/test/PreOrderTreeWalker.java Mon Aug 30 00:48:50 2010 +0900 @@ -22,28 +22,25 @@ } class IteratorState implements Iterator<NodeAPI> { LinkedList<NodeState>nodeStack; - List<NodeAPI> children; int position; NodeAPI current, next; IteratorState(NodeAPI root) { current = root; - children = root.getChildList(); position = 0; nodeStack = new LinkedList<NodeState>(); } public boolean hasNext() { - while (position>=children.size()) { + while (position>=current.getChildList().size()) { if (nodeStack.isEmpty()) return false; - children = nodeStack.getLast().node.getChildList(); - position = nodeStack.getLast().position; - nodeStack.removeLast(); + NodeState s = nodeStack.poll(); + current = s.node; + position = s.position; } - next = children.get(position++); + next = current.getChildList().get(position++); if (! next.getChildList().isEmpty()) { nodeStack.addLast(new NodeState(current,position)); current = next; - children = next.getChildList(); position = 0; } return true;