added binary expressions

This commit is contained in:
2018-05-07 11:42:25 +02:00
parent 3ce0505f4e
commit dcaf7f0775
2 changed files with 47 additions and 12 deletions

View File

@@ -1,12 +1,20 @@
package worms.programs;
public abstract class BinaryExpression<L, R> implements Expression {
import java.util.function.BinaryOperator;
import java.util.function.DoubleBinaryOperator;
protected final L left;
protected final R right;
public abstract class BinaryExpression implements Expression {
public BinaryExpression(L left, R right) {
protected final Object left;
protected final Object right;
public BinaryExpression(Object left, Object right) {
this.left = left;
this.right = right;
}
@SuppressWarnings("unchecked")
protected Object execute(BinaryOperator op) {
return op.apply(this.left, this.right);
}
}