public String PPrint(int indent, boolean recursive) { String output = new String(); if (children.size() == 0) { output += doIndent(indent) + "<" + label + "/>\n"; } else { output += doIndent(indent) + "<" + label + ">\n"; indent += 2; if (recursive) { for (int i = 0; i < children.size(); i++) { Walkable w = (Walkable) children.elementAt(i); output += w.PPrint(indent, true); } } else { for (int i = 0; i < children.size(); i++) { Walkable w = (Walkable) children.elementAt(i); output += doIndent(indent) + "<" + w.getNodeName() + "/>\n"; } } indent -= 2; output += doIndent(indent) + "</" + label + ">\n"; } return output; }
public ParseNodeVector getChildren(String label) { int i; ParseNodeVector v = new ParseNodeVector(); for (i = 0; i < children.size(); i++) { ParseNode pn = children.elementAt(i); if (pn.getLabel().equals(label)) v.addElement(pn); } return v; }
public ParseNode getChild(String label) { int i; ParseNode p; for (i = 0; i < children.size(); i++) { p = children.elementAt(i); if (p.getLabel().equals(label)) { return p; } } return null; }
public ParseNode addChild(String newlabel) { ParseNode child = new ParseNode(newlabel, -1); children.addElement(child); child.setParent(this); return child; }
public ParseNode addChild(ParseNode child) { if (child == null) throw new NullPointerException("Can't add null node to parse tree"); children.addElement(child); child.setParent(this); return child; }
public String getTerminal() { ParseNode pn = children.elementAt(0); if (pn == null) { return null; } else { return pn.getLabel(); } }
public ParseNode insertChild(ParseNode child) { if (child == null) { throw new NullPointerException("Can't add null node to parse tree"); } children.insertElementAt(child, 0); child.setParent(this); return child; }
public Object getNeighbor(int index) { return children.elementAt(index); }
public int getNeighborCount() { return children.size(); }