mirror of
https://github.com/DanilaFe/abacus
synced 2026-01-26 16:45:21 +00:00
Format code.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user