Changeset 1579 for branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/SimpleTree.java
- Timestamp:
- 06/25/14 22:02:05 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/SimpleTree.java
r1573 r1579 10 10 11 11 import java.io.PrintWriter; 12 import java.io.Serializable;13 12 import java.io.StringWriter; 14 import java.util.Hashtable; 13 15 14 16 15 import de.ugoe.cs.autoquest.tasktrees.alignment.pal.misc.Identifier; 17 import de.ugoe.cs.autoquest.tasktrees.alignment.pal.misc.LabelMapping; 16 18 17 19 18 … … 56 55 private int numExternalNodes; 57 56 58 /** attributes attached to this tree. */59 private Hashtable[] attributes = null;60 61 62 63 57 /** constructor tree consisting solely of root node */ 64 58 public SimpleTree() { … … 77 71 createNodeList(); 78 72 } 79 80 /** clone constructor */81 public SimpleTree(Tree tree)82 {83 root = new FengDoolittleNode(tree.getRoot());84 createNodeList();85 }86 87 /** clone constructor */88 public SimpleTree(Tree tree, boolean keepIdentifiers)89 {90 root = new FengDoolittleNode(tree.getRoot(), keepIdentifiers);91 createNodeList();92 }93 /**94 * clone constructor95 * @param lm - a label mapping use for translating the original label names into something else96 */97 public SimpleTree(Tree tree, LabelMapping lm)98 {99 root = new FengDoolittleNode(tree.getRoot(), lm);100 createNodeList();101 }102 103 73 104 74 … … 225 195 } 226 196 227 private int getIndex(Node node) { 228 if (node.isLeaf()) return node.getNumber(); 229 return getExternalNodeCount() + node.getNumber(); 230 } 231 232 /** 233 * Sets an named attribute for a given node. 234 * @param node the node whose attribute is being set. 235 * @param name the name of the attribute. 236 * @param value the new value of the attribute. 237 */ 238 public void setAttribute(Node node, String name, Object value) { 239 if (node instanceof AttributeNode) { 240 ((AttributeNode)node).setAttribute(name, value); 241 } else { 242 int index = getIndex(node); 243 if (attributes == null) { 244 attributes = new Hashtable[getExternalNodeCount() + getInternalNodeCount()]; 245 } 246 if (attributes[index] == null) { 247 attributes[index] = new Hashtable(); 248 } 249 attributes[index].put(name, value); 250 } 251 } 197 198 252 199 253 200 public String toString() { … … 258 205 } 259 206 260 /**261 * @return an object representing the named attributed for the numbered node.262 * @param node the node being interrogated.263 * @param name the name of the attribute of interest.264 */265 public Object getAttribute(Node node, String name) {266 if (node instanceof AttributeNode) {267 return ((AttributeNode)node).getAttribute(name);268 } else {269 int index = getIndex(node);270 if (attributes == null || attributes[index] == null) {271 return null;272 }273 return attributes[index].get(name);274 }275 }276 207 277 208
Note: See TracChangeset
for help on using the changeset viewer.