package org.nwapw.abacus.tree;

import org.nwapw.abacus.number.NumberInterface;
import org.nwapw.abacus.plugin.PluginManager;

public class NumberReducer implements Reducer<NumberInterface> {

    private PluginManager manager;

    public NumberReducer(PluginManager manager){
        this.manager = manager;
    }

    @Override
    public NumberInterface reduceNode(TreeNode node, Object... children) {
        if(node instanceof NumberNode) {
            return ((NumberNode) node).getNumber();
        } else if(node instanceof OpNode){
            NumberInterface left = (NumberInterface) children[0];
            NumberInterface right = (NumberInterface) children[1];
            return manager.functionFor(((OpNode) node).getOperation()).apply(left, right);
        }
        return null;
    }

}

@@ -25,16 +25,59 @@
 .tree;%0A%0A
+import org.nwapw.abacus.function.Function;%0A
 import o
@@ -116,16 +116,16 @@
 erface;%0A
-
 import o
@@ -723,22 +723,35 @@
         
-return
+Function function =
  manager
@@ -798,26 +798,575 @@
 n())
-.apply(left, right
+;%0A            if(function == null) return null;%0A            return function.apply(left, right);%0A        %7D else if(node instanceof FunctionNode)%7B%0A            NumberInterface%5B%5D convertedChildren = new NumberInterface%5Bchildren.length%5D;%0A            for(int i = 0; i %3C convertedChildren.length; i++)%7B%0A                convertedChildren%5Bi%5D = (NumberInterface) children%5Bi%5D;%0A            %7D%0A            Function function = manager.functionFor(((FunctionNode) node).getFunction());%0A            if(function == null) return null;%0A            return function.apply(convertedChildren
 );%0A 

Implement reducing functions.