1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-11 09:35:23 +00:00

Add a new constructor to the UI, and move strings into constants.

This commit is contained in:
2017-07-26 13:31:05 -07:00
parent 9ce35aad54
commit 53b9b56039
3 changed files with 64 additions and 6 deletions

View File

@@ -0,0 +1,26 @@
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;
}
}