1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-04 15:32:59 -08:00

Switch add and multiply to two parameters.

This commit is contained in:
Danila Fedorin 2017-08-29 18:31:47 -07:00
parent 337a38a07d
commit ae0ec0c375

View File

@ -21,16 +21,12 @@ public class StandardPlugin extends Plugin {
public static final NumberOperator OP_ADD = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0) {
@Override
public boolean matchesParams(NumberInterface[] params) {
return params.length >= 1;
return params.length == 2;
}
@Override
public NumberInterface applyInternal(NumberInterface[] params) {
NumberInterface sum = params[0];
for (int i = 1; i < params.length; i++) {
sum = sum.add(params[i]);
}
return sum;
return params[0].add(params[1]);
}
};
/**
@ -68,16 +64,12 @@ public class StandardPlugin extends Plugin {
public static final NumberOperator OP_MULTIPLY = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1) {
@Override
public boolean matchesParams(NumberInterface[] params) {
return params.length >= 1;
return params.length == 2;
}
@Override
public NumberInterface applyInternal(NumberInterface[] params) {
NumberInterface product = params[0];
for (int i = 1; i < params.length; i++) {
product = product.multiply(params[i]);
}
return product;
return params[0].multiply(params[1]);
}
};
/**