Methods Summary |
---|
protected java.lang.Object | buildChild(java.lang.Object o)
if ((o instanceof Integer) || (o instanceof OpNode)) {
return o;
}
String op = null;
if (o instanceof String) {
op = ((String)o).trim();
if (op.equals(ADD)) { return new OpNode(ADD); }
else if (op.equals(SUBTRACT)) { return new OpNode(SUBTRACT); }
else if (op.equals(MULTIPLY)) { return new OpNode(MULTIPLY); }
else if (op.equals(DIVIDE)) { return new OpNode(DIVIDE); }
else {
try { return Integer.valueOf(op); }
catch (NumberFormatException nfe) { return new Integer(0); }
}
}
System.err.println("Fell through new child: " + op);
return new Integer(0);
|
protected void | buildCollapsedString(java.lang.StringBuffer buf, java.lang.Object node)
if (node == null) { return; }
if (node instanceof OpNode) {
buf.append("(");
buildCollapsedString(buf, ((OpNode)node).getChild(0));
buf.append(" ");
buf.append(((OpNode)node).getOperator());
buf.append(" ");
buildCollapsedString(buf, ((OpNode)node).getChild(1));
buf.append(")");
}
else { buf.append(node); }
|
public java.lang.Object | getChild(int index)
if (index == 0) { return children[0]; }
else if (index == 1) { return children[1]; }
throw new IllegalArgumentException("child index must be 0 or 1");
|
public int | getChildCount()
int count = 0;
if (children[0] != null) { count++; }
if (children[1] != null) { count++; }
return count;
|
public int | getIndexOfChild(java.lang.Object child)
if (child.equals(children[0])) { return 0; }
else if (child.equals(children[1])) { return 1; }
return -1;
|
public java.lang.String | getOperator() return operator;
|
public void | setChild(int index, java.lang.Object child)
if (index == 0) { children[0] = buildChild(child); }
else if (index == 1) { children[1] = buildChild(child); }
else {
throw new IllegalArgumentException("child index " + index
+ " must be 0 or 1");
}
|
public void | setExpanded(boolean b) expanded = b;
|
public void | setOperator(java.lang.Object op)
if (op instanceof String) { operator = (String)op; }
else {
throw new IllegalArgumentException("operators must be strings");
}
|
public java.lang.String | toString()
if (expanded) { return operator; }
else {
StringBuffer buf = new StringBuffer(40);
buildCollapsedString(buf, this);
return buf.toString();
}
|