1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 15:30:09 -08:00

Add the withReducer variants of the Applier functions.

This commit is contained in:
Danila Fedorin 2017-08-25 01:41:32 -07:00
parent 6b9252f902
commit 26305c3bae

View File

@ -1,6 +1,7 @@
package org.nwapw.abacus.function; package org.nwapw.abacus.function;
import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.number.NumberInterface;
import org.nwapw.abacus.tree.Reducer;
import org.nwapw.abacus.tree.TreeNode; import org.nwapw.abacus.tree.TreeNode;
/** /**
@ -9,4 +10,34 @@ import org.nwapw.abacus.tree.TreeNode;
*/ */
public abstract class TreeValueFunction extends Applicable<TreeNode, NumberInterface> { public abstract class TreeValueFunction extends Applicable<TreeNode, NumberInterface> {
@Override
protected NumberInterface applyInternal(TreeNode[] params) {
return null;
}
@Override
public NumberInterface apply(TreeNode... params) {
return null;
}
/**
* Applies the tree value functions to the given tree nodes,
* using the given reducer.
* @param reducer the reducer to use.
* @param params the parameters to apply to.
* @return the result of the application.
*/
public abstract NumberInterface applyWithReducerInternal(Reducer<NumberInterface> reducer, TreeNode[] params);
/**
* Checks if the given parameters and reducer can be used
* with this function, and if so, calls the function on them.
* @param reducer the reducer to use.
* @param params the parameters to apply to.
* @return the result of the application, or null if the parameters are incompatible.
*/
public NumberInterface applyWithReducer(Reducer<NumberInterface> reducer, TreeNode... params) {
if(!matchesParams(params) || reducer == null) return null;
return applyWithReducerInternal(reducer, params);
}
} }