1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-26 16:45:21 +00:00

Format code.

This commit is contained in:
2017-07-30 21:11:32 -07:00
parent 122874b97a
commit 3ce74303ed
39 changed files with 695 additions and 561 deletions

View File

@@ -17,34 +17,35 @@ public class NumberReducer implements Reducer<NumberInterface> {
/**
* Creates a new number reducer.
*
* @param abacus the calculator instance.
*/
public NumberReducer(Abacus abacus){
public NumberReducer(Abacus abacus) {
this.abacus = abacus;
}
@Override
public NumberInterface reduceNode(TreeNode node, Object... children) {
if(node instanceof NumberNode) {
if (node instanceof NumberNode) {
return ((NumberNode) node).getNumber();
} else if(node instanceof BinaryInfixNode){
} else if (node instanceof BinaryInfixNode) {
NumberInterface left = (NumberInterface) children[0];
NumberInterface right = (NumberInterface) children[1];
Function function = abacus.getPluginManager().operatorFor(((BinaryInfixNode) node).getOperation()).getFunction();
if(function == null) return null;
if (function == null) return null;
return function.apply(left, right);
} else if(node instanceof UnaryPrefixNode) {
} else if (node instanceof UnaryPrefixNode) {
NumberInterface child = (NumberInterface) children[0];
Function functionn = abacus.getPluginManager().operatorFor(((UnaryPrefixNode) node).getOperation()).getFunction();
if(functionn == null) return null;
if (functionn == null) return null;
return functionn.apply(child);
} else if(node instanceof FunctionNode){
} else if (node instanceof FunctionNode) {
NumberInterface[] convertedChildren = new NumberInterface[children.length];
for(int i = 0; i < convertedChildren.length; i++){
for (int i = 0; i < convertedChildren.length; i++) {
convertedChildren[i] = (NumberInterface) children[i];
}
Function function = abacus.getPluginManager().functionFor(((FunctionNode) node).getFunction());
if(function == null) return null;
if (function == null) return null;
return function.apply(convertedChildren);
}
return null;