package tools;

import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;

public class ConfigTree {
	public ConfigTree parent ;
	public String name ;
	public String path ;
	public String part ;
	public Collection<Condition> conditions ;
	public boolean complex ;
	
	public HashMap<String, ConfigTree> children ;
	
	public ConfigTree(String part) {
		this.part = part ;
		this.path = getPath(part) ;
		this.name = null ;
		this.parent = null ;
		this.children = new HashMap<String, ConfigTree>() ;
		this.conditions = new TreeSet<Condition>() ;
		this.complex = false ;
	}
	
	public ConfigTree(String part, String name) {
		this(part) ;
		this.name = name ;
	}
	
	public ConfigTree(String part, String name, ConfigTree parent) {
		this(part, name) ;
		this.parent = parent ;
	}
	
	public void addChild(ConfigTree child) {
		this.children.put(child.part, child) ;
	}

	public ConfigTree getChild(String part) {
		return this.children.get(part) ;
	}
	public void addCondition(String fieldName, String fieldValue) {
		this.conditions.add(new Condition(fieldName, fieldValue)) ;
	}
	public void setComplex() {
		this.complex = true ;		
	}
	public boolean isComplex() {
		return this.complex ;
	}
	
	public String getPath(String path) {
		if (path.indexOf("[") != -1) {
			return path.substring(0, path.indexOf("[")) ;
		}
		else {
			return path ;
		}
	}
}
