From 26305c3baef925467c1ebe7af996fc551a7c24b8 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 25 Aug 2017 01:41:32 -0700 Subject: [PATCH] Add the withReducer variants of the Applier functions. --- .../abacus/function/TreeValueFunction.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core/src/main/java/org/nwapw/abacus/function/TreeValueFunction.java b/core/src/main/java/org/nwapw/abacus/function/TreeValueFunction.java index cd802c4..a34cecc 100644 --- a/core/src/main/java/org/nwapw/abacus/function/TreeValueFunction.java +++ b/core/src/main/java/org/nwapw/abacus/function/TreeValueFunction.java @@ -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 { + @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 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 reducer, TreeNode... params) { + if(!matchesParams(params) || reducer == null) return null; + return applyWithReducerInternal(reducer, params); + } }