view src/treecms/proto/test/SearchPathTest1.java @ 26:9b91329e8a04

commit for zemi , doent move
author ShoshiTAMAKI
date Tue, 02 Nov 2010 18:44:21 +0900
parents e950264f82d3
children
line wrap: on
line source

package treecms.proto.test;

import java.util.Iterator;

import java.util.LinkedList;

import treecms.proto.api.*;
import treecms.proto.simple.*;

public class SearchPathTest1
{
	public static void main(String _arg[])
	{
		TreeBuilder builder = new SimpleTreeBuilder();
		Node root = builder.getContents();
		root.setTitle("root");
		
		Node child1 = builder.createNode();
		child1.setTitle("+-child1");
		Node child2 = builder.createNode();
		child2.setTitle("+-child2");
		
		root.addChild(child1);
		root.addChild(child2);
		
		Node child11 = builder.createNode(); 
		child11.setTitle(" +-child11");
		Node child12 = builder.createNode();
		child12.setTitle(" +-child12");
		Node child13 = builder.createNode();
		child13.setTitle(" +-child13");
		
		child1.addChild(child11);
		child1.addChild(child12);
		child1.addChild(child13);
		
		Node child21 = builder.createNode();
		child21.setTitle(" +-child21");
		
		child2.addChild(child21);
		
		Node child211 = builder.createNode();
		child211.setTitle("  +-child211");
		Node child212 = builder.createNode();
		child212.setTitle("  +-child212");
		
		child21.addChild(child211);
		child21.addChild(child212);
		
		
		PreOrderTreeWalkerRecursive walker = new PreOrderTreeWalkerRecursive(root);
		Iterator<Node> itr = walker.iterator();
		
		LinkedList<Node> reverse = new LinkedList<Node>();
		while(itr.hasNext()){
			reverse.addFirst(itr.next());
		}
		
		Node target = child212;
		LinkedList<Node> path = new LinkedList<Node>();
		for(Node node : reverse){
			if(node.isChild(target)){
				path.addFirst(target);
				target = node;
			}
		}
		
		for(Node node : path){
			System.out.println(node.getTitle());
		}
	}
}