feat: update structure
This commit is contained in:
38
cs2030s/labs/Lab6/Or.java
Normal file
38
cs2030s/labs/Lab6/Or.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Represents the Or type, a conditional which returns true if either value is
|
||||
* true. This operator short circuits, which means that if the left value is
|
||||
* true, the right value is not evaluated
|
||||
*/
|
||||
class Or implements Cond {
|
||||
private Cond lVal;
|
||||
private Cond rVal;
|
||||
|
||||
/**
|
||||
* Constructor for the Or conditional.
|
||||
*
|
||||
* @param lVal the left value in the Or Operation.
|
||||
* @param rVal This is only evaluated if lVal is false
|
||||
*/
|
||||
public Or(Cond lVal, Cond rVal) {
|
||||
this.lVal = lVal;
|
||||
this.rVal = rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eval() {
|
||||
if (this.lVal.eval()) {
|
||||
return true;
|
||||
}
|
||||
return this.rVal.eval();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + this.lVal + " | " + this.rVal + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cond neg() {
|
||||
return new And(lVal.neg(), rVal.neg());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user