00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package dochelper;
00011
00012 import java.util.ArrayList;
00013 import java.util.HashMap;
00014 import java.util.List;
00015
00016
00026 public class ResultNode {
00027
00031 private HashMap _params;
00032
00036 private ArrayList<ResultNode> _children;
00037
00041 private String _value;
00042
00046 public String _name;
00047
00053 public ResultNode(String value, HashMap params, String name) {
00054 this._value = value;
00055 this._params = params;
00056 this._name = name;
00057 }
00058
00065 public void addChild(ResultNode node) {
00066
00067 if (_children == null)
00068 _children = new ArrayList<ResultNode>();
00069
00070 _children.add(node);
00071 }
00072
00079 public List<ResultNode> getChildren() {
00080 return _children;
00081 }
00082
00089 public String getValue() {
00090 return _value;
00091 }
00092
00099 public HashMap getParams() {
00100 return _params;
00101 }
00102
00110 public ResultNode find(String nodeName) {
00111 if (nodeName.equals(_name)){
00112 return this;
00113 } else {
00114 List<ResultNode> children = this.getChildren();
00115
00116 for(ResultNode child : children) {
00117 if (nodeName.equals(child._name)){
00118 return child;
00119 }
00120 }
00121
00122 for(ResultNode child : children) {
00123 ResultNode childResult = child.find(nodeName);
00124
00125 if (childResult != null) {
00126 return childResult;
00127 }
00128 }
00129 }
00130
00131 return null;
00132 }
00133
00144 public boolean hasLeaf() {
00145
00146
00147 if(this.isLeaf())
00148 return false;
00149
00150
00151 for(ResultNode child : this.getChildren()) {
00152 if(child.isLeaf())
00153 return true;
00154 }
00155
00156
00157 return false;
00158 }
00159
00160
00167 public boolean isLeaf() {
00168 return ( this.getChildren()==null || this.getChildren().size()==0);
00169 }
00170
00171
00172 public String toString() {
00173 return "Result Node: [" + this._name + ", " + this._value + ", Num Children: " + ((_children!=null)?_children.size():"No children") + "]";
00174 }
00175 }