changeset 6:1c67e35efd1c

fix iterator
author one
date Sat, 28 Aug 2010 15:40:49 +0900
parents 1bbee0534ece
children 18f696e9fc1e
files src/treecms/proto/test/PreOrderTreeWalker.java
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/treecms/proto/test/PreOrderTreeWalker.java	Fri Aug 27 22:56:22 2010 +0900
+++ b/src/treecms/proto/test/PreOrderTreeWalker.java	Sat Aug 28 15:40:49 2010 +0900
@@ -24,13 +24,13 @@
 		LinkedList<NodeState>nodeStack;
 		List<NodeAPI> children;
 		int position;
-		NodeAPI next;
+		NodeAPI current, next;
 		
 		IteratorState(NodeAPI root) {
+			current = root;
 			children = root.getChildList();
+			position = 0;
 			nodeStack = new LinkedList<NodeState>();
-			nodeStack.addLast(new NodeState(root,0));
-			position = 0;
 		}
 
 		public boolean hasNext() {
@@ -42,7 +42,8 @@
 			}
 			next = children.get(position++);
 			if (! next.getChildList().isEmpty()) {
-				nodeStack.addLast(new NodeState(next,position));
+				nodeStack.addLast(new NodeState(current,position));
+				current = next;
 				children = next.getChildList();
 				position = 0;
 			}