Return to Snippet

Revision: 66126
at March 18, 2014 16:40 by muzahidict


Initial Code
import java.util.ArrayList;
import java.util.List;

/**
 * To generate a tree by given string content
 * @author MD. MUZAHIDUL ISLAM ([email protected])
 * */
public class TreeNode {

	TreeNode parentNode;
	String content = "";
	String trace = "";
	List<TreeNode> childNodes = new ArrayList<TreeNode>();
	int depth = 0;
	int level = 0;
	
	String options;
	
	public static TreeNode root = null;
	public static List<TreeNode> leafs;
	
	
	public TreeNode(TreeNode parentNode, String content, String trace, int level, int depth, String options){
		this.parentNode = parentNode;
		this.content = content;
		this.trace =trace;
		this.level = level;
		this.depth = depth;
		this.options = options;
		if (level < depth) {
			createChild(options);
		}
		else {
			leafs.add(this);
		}
	}

	public TreeNode(boolean isRoot, TreeNode parentNode, String content, String trace, int level, int depth, String options){
		if(isRoot){
			leafs = new ArrayList<TreeNode>();
		}
		this.parentNode = parentNode;
		this.content = content;
		this.trace =trace;
		this.level = level;
		this.depth = depth;
		this.options = options;
		if (level < depth) {
			createChild(options);
		}
		else {
			leafs.add(this);
		}
	}
	
	public void createChild(String options) {
		for(char c : options.toCharArray()){
			childNodes.add(new TreeNode(this, ""+c, this.trace+c, this.level+1, this.depth, this.options));
		}
	}
}

Initial URL

                                

Initial Description
This is a java class to generate a tree by given string content

Initial Title
Tree Generation by given string content using JAVA

Initial Tags
java

Initial Language
Java