changeset 5:1bbee0534ece

container
author one
date Fri, 27 Aug 2010 22:56:22 +0900
parents 8c33fd63fea6
children 1c67e35efd1c
files src/treecms/proto/test/PreOrderTreeWalker.java
diffstat 1 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/treecms/proto/test/PreOrderTreeWalker.java	Fri Aug 27 22:51:03 2010 +0900
+++ b/src/treecms/proto/test/PreOrderTreeWalker.java	Fri Aug 27 22:56:22 2010 +0900
@@ -15,34 +15,34 @@
 		m_root = _root;
 	}
 	
+	class NodeState {
+		NodeAPI node;
+		int position;
+		NodeState(NodeAPI n,int p) { node = n; position = p; }
+	}
 	class IteratorState implements Iterator<NodeAPI> {
-		LinkedList<NodeAPI>nodeStack;
-		LinkedList<Integer>positionStack;
+		LinkedList<NodeState>nodeStack;
 		List<NodeAPI> children;
 		int position;
 		NodeAPI next;
 		
 		IteratorState(NodeAPI root) {
 			children = root.getChildList();
-			nodeStack = new LinkedList<NodeAPI>();
-			positionStack = new LinkedList<Integer>();
-			nodeStack.addLast(root);
-			positionStack.addLast(0);
+			nodeStack = new LinkedList<NodeState>();
+			nodeStack.addLast(new NodeState(root,0));
 			position = 0;
 		}
 
 		public boolean hasNext() {
 			while (position>=children.size()) {
 				if (nodeStack.isEmpty()) return false;
-				children = nodeStack.getLast().getChildList();
-				position = positionStack.getLast();
+				children = nodeStack.getLast().node.getChildList();
+				position = nodeStack.getLast().position;
 				nodeStack.removeLast();
-				positionStack.removeLast();
 			}
 			next = children.get(position++);
 			if (! next.getChildList().isEmpty()) {
-				nodeStack.addLast(next);
-				positionStack.addLast(position);
+				nodeStack.addLast(new NodeState(next,position));
 				children = next.getChildList();
 				position = 0;
 			}