package gve.calc.formula;

public class OperatorCompare extends InfixBinaryOp {
	/* < > <= >= */
	private String opname;

	public OperatorCompare(String nam,Part l,Part r) {
		super(l,r);
		opname = nam;
	}

	public String getName() { return opname; }
	public int getPri() { return 1700; }

	public boolean same(Object o) {
		o = Brackets.unbracket(o);
		if (o instanceof OperatorCompare) {
			OperatorCompare cmp = (OperatorCompare)o;
			return opname.equals(cmp.opname) && left.same(cmp.left) && right.same(cmp.right);
		}
		return false;
	}

	public Part evaluate(Evaluator ev) {
		return new OperatorCompare(opname,left.evaluate(ev),right.evaluate(ev));
	}

	public void write(java.io.Writer w) throws java.io.IOException {
		super.write(w);
		w.write(opname+"\n");
	}

	public static Part read(java.io.BufferedReader r) throws java.io.IOException,
			ClassNotFoundException,NoSuchMethodException,
			java.lang.reflect.InvocationTargetException,IllegalAccessException{
		Part left = Part.read(r);
		Part right = Part.read(r);
		return new OperatorCompare(r.readLine(),left,right);
	}
}