1 23 24 package org.objectweb.clif.scenario.util.isac.util.tree; 25 26 import java.util.Vector ; 27 28 import org.apache.log4j.Category; 29 36 public class ScenarioNode { 37 static Category cat = Category.getInstance(ScenarioNode.class.getName()); 38 private String key; 39 private ScenarioNode parent; 40 private Vector children; 41 42 46 public ScenarioNode() { 47 cat.debug("-> constructor"); 48 this.key = null; 49 this.parent = null; 50 this.children = new Vector (); 51 } 52 53 60 public ScenarioNode(String key) { 61 cat.debug("-> constructor"); 62 this.key = key; 63 this.parent = null; 64 this.children = new Vector (); 65 } 66 67 76 public ScenarioNode(String key, ScenarioNode parent) { 77 cat.debug("-> constructor"); 78 this.key = key; 79 this.parent = parent; 80 this.children = new Vector (); 81 } 82 83 89 public String getKey() { 90 cat.debug("-> getKey"); 91 return this.key; 92 } 93 94 99 public ScenarioNode getParent() { 100 cat.debug("-> getParent"); 101 return this.parent; 102 } 103 104 109 public Vector getChildren() { 110 cat.debug("-> getChildren"); 111 return this.children; 112 } 113 114 120 public void setKey(String key) { 121 cat.debug("-> setKey"); 122 this.key = key; 123 } 124 125 131 public void setParent(ScenarioNode p) { 132 cat.debug("-> setParent"); 133 this.parent = p; 134 } 135 136 142 public void setChildren(Vector children) { 143 cat.debug("-> setChildren"); 144 this.children = children; 145 } 146 147 153 public void addChild(ScenarioNode child) { 154 cat.debug("-> addChild"); 155 child.setParent(this); 156 this.children.add(child); 157 } 158 159 165 public void removeChild(ScenarioNode child) { 166 cat.debug("-> removeChild"); 167 this.children.remove(child); 168 } 169 170 177 public boolean equals(ScenarioNode child) { 178 cat.debug("-> equals"); 179 return (child.getKey()).equals(this.key); 180 } 181 182 185 public void delete() { 186 cat.debug("-> delete"); 187 if (this.parent != null) { 188 this.parent.removeChild(this); 189 } 190 } 191 192 199 public boolean contains(ScenarioNode node) { 200 cat.debug("-> contains"); 201 if (node.equals(this)) 202 return true; 203 for (int i = 0; i < this.children.size(); i++) 205 if (((ScenarioNode) this.children.elementAt(i)).contains(node)) 206 return true; 207 return false; 209 } 210 211 217 public void childUpper(String key) { 218 cat.debug("-> childUpper"); 219 int number = 0; 221 for (int i = 0; i < this.children.size(); i++) { 222 if ((((ScenarioNode) this.children.elementAt(i)).getKey()) 223 .equals(key)) { 224 number = i; 225 break; 226 } 227 } 228 if (number == 0) 229 return; 230 ScenarioNode child = (ScenarioNode) this.children.elementAt(number); 231 this.children.remove(number); 232 this.children.add(number - 1, child); 233 } 234 235 241 public void childLower(String key) { 242 cat.debug("-> childLower"); 243 int number = this.children.size(); 245 for (int i = 0; i < this.children.size(); i++) { 246 if ((((ScenarioNode) this.children.elementAt(i)).getKey()) 247 .equals(key)) { 248 number = i; 249 break; 250 } 251 } 252 if (number == this.children.size() - 1) 253 return; 254 ScenarioNode child = (ScenarioNode) this.children.elementAt(number); 255 this.children.remove(number); 256 this.children.add(number + 1, child); 257 } 258 259 265 public String toString() { 266 cat.debug("-> toString"); 267 String result = ""; 268 result = result.concat("key : " + this.key + "\n"); 269 result = result.concat("nb children : " + this.children.size() + "\n"); 270 275 return result; 276 } 277 278 281 public void printTest() { 282 cat.warn(TreeManager.getTreeManager(null).getNodeType(this)); 283 if (children != null) { 284 cat.warn("["); 285 for (int i = 0; i < children.size(); i++) 286 ((ScenarioNode) children.elementAt(i)).printTest(); 287 cat.warn("]"); 288 } 289 } 290 } | Popular Tags |