mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Add the withReducer variants of the Applier functions.
This commit is contained in:
parent
6b9252f902
commit
26305c3bae
|
@ -1,6 +1,7 @@
|
|||
package org.nwapw.abacus.function;
|
||||
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
import org.nwapw.abacus.tree.Reducer;
|
||||
import org.nwapw.abacus.tree.TreeNode;
|
||||
|
||||
/**
|
||||
|
@ -9,4 +10,34 @@ import org.nwapw.abacus.tree.TreeNode;
|
|||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user