package gve.calc.logic;

import java.awt.*;
import gve.calc.formula.*;

A formula with one (right==null) or two (right!=null) children
public class TableauPart extends Part {
right can be null; top and left always are !=null
public Part top,left,right; private TableauPart(Part t) { top = t; t.setParent(this); } public TableauPart(Part t,Part ch) { this(t); left = ch; ch.setParent(this); } public TableauPart(Part t,Part l,Part r) { this(t,l); right = r; r.setParent(this); } public Part getChild(int count) { switch (count) { case 0: return top; case 1: return left; case 2: return right; default: return null; } }
Returns true if this part has already been reduced. Visibly; this condition is the same as "has p a line originating downwards?".
public static boolean hasReduction(Part p) { if (p.getParent() instanceof TableauPart) { TableauPart tp = (TableauPart)p.getParent(); if (tp.top == p) return true; } return false; } public Object clone() { return new TableauPart(top,left,right); } public Part evaluate(Evaluator ev) { return null; } public void replaceChild(Part ch,Part byThat) { if (ch == left) { left = byThat; byThat.setParent(this); } else if (ch == top) { top = byThat; byThat.setParent(this); } else if (ch == right) { right = byThat; byThat.setParent(this); } } public String toString() { String r; if (right == null) r = ""; else r = ", right="+right; return "TableauPart[top="+top+", left="+left+r+"]"; } public Component createView(FormulaView view) { return new TableauPartView(this,view); } public void write(java.io.Writer w) throws java.io.IOException { super.write(w); int count = (right == null) ? 1 : 2; w.write(count+"\n"); top.write(w); left.write(w); if (right != null) right.write(w); } public static Part read(java.io.BufferedReader r) throws java.io.IOException, ClassNotFoundException,NoSuchMethodException, java.lang.reflect.InvocationTargetException,IllegalAccessException { int count = Integer.parseInt(r.readLine()); Part top = Part.read(r); Part left = Part.read(r); if (count > 1) { Part right = Part.read(r); return new TableauPart(top,left,right); } return new TableauPart(top,left); } }