/** Our internal representation of a Ifnz * in the S0 language. * See http://www.radford.edu/itec380/2017fall-ibarland/Project * * @author Ian Barland * @version 2016.Nov.09 */ public class Ifnz extends Expr { static final String TOKEN = "("; Expr cond, nzBranch, zBranch; Ifnz( Expr _cond, Expr _nzBranch, Expr _zBranch) { this.cond = _cond; this.nzBranch = _nzBranch; this.zBranch = _zBranch; } public String toString() { return TOKEN + this.cond.toString() + ") !0 " + this.nzBranch.toString() + " : " + this.zBranch.toString() ; } static final double EPSILON = 1e-10; public Value eval() { if (!(Math.abs(((Num)(cond.eval())).doubleValue()) < EPSILON)) { return this.nzBranch.eval(); } else { return this.zBranch.eval(); } } @Override public boolean equals( /* Ifnz this, */ Object that) { if (this==that) { return true; } else if (that==null) { return false; } else if (this.getClass() != that.getClass()) { return false; } else { Ifnz thatt = (Ifnz) that; return this.cond.equals(thatt.cond) && this.nzBranch.equals(thatt.nzBranch) && this.zBranch.equals(thatt.zBranch); } } @Override public int hashCode() { if (cachedHash == null) { int hashSoFar = (int)0x314d2ef361bcd159L; // fingerprint hashSoFar += this.cond.hashCode(); hashSoFar *= 31; hashSoFar += this.nzBranch.hashCode(); hashSoFar *= 31; hashSoFar += this.zBranch.hashCode(); cachedHash = hashSoFar; } return cachedHash; } private Integer cachedHash = null; }