From f83f2a7aaae48cf97e999bce5e25a139e488d34a Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 25 Aug 2017 14:56:36 -0700 Subject: [PATCH] Rename Function to NumberFunction. --- .../{Function.java => NumberFunction.java} | 2 +- .../java/org/nwapw/abacus/plugin/Plugin.java | 5 +-- .../nwapw/abacus/plugin/PluginManager.java | 6 +-- .../nwapw/abacus/plugin/StandardPlugin.java | 37 +++++++++---------- .../org/nwapw/abacus/tree/NumberReducer.java | 5 +-- .../nwapw/abacus/tests/TokenizerTests.java | 2 +- 6 files changed, 26 insertions(+), 31 deletions(-) rename core/src/main/java/org/nwapw/abacus/function/{Function.java => NumberFunction.java} (65%) diff --git a/core/src/main/java/org/nwapw/abacus/function/Function.java b/core/src/main/java/org/nwapw/abacus/function/NumberFunction.java similarity index 65% rename from core/src/main/java/org/nwapw/abacus/function/Function.java rename to core/src/main/java/org/nwapw/abacus/function/NumberFunction.java index 9ee9509..24461c2 100755 --- a/core/src/main/java/org/nwapw/abacus/function/Function.java +++ b/core/src/main/java/org/nwapw/abacus/function/NumberFunction.java @@ -6,6 +6,6 @@ import org.nwapw.abacus.number.NumberInterface; * A function that operates on one or more * inputs and returns a single number. */ -public abstract class Function extends Applicable { +public abstract class NumberFunction extends Applicable { } diff --git a/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java b/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java index 1e6763f..229df85 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java @@ -1,7 +1,6 @@ package org.nwapw.abacus.plugin; import org.nwapw.abacus.function.*; -import org.nwapw.abacus.number.NaiveNumber; import org.nwapw.abacus.number.NumberInterface; /** @@ -63,7 +62,7 @@ public abstract class Plugin { * @param name the name to register by. * @param toRegister the function implementation. */ - protected final void registerFunction(String name, Function toRegister) { + protected final void registerFunction(String name, NumberFunction toRegister) { manager.registerFunction(name, toRegister); } @@ -119,7 +118,7 @@ public abstract class Plugin { * @param name the name for which to search * @return the resulting function, or null if none was found for that name. */ - protected final Function functionFor(String name) { + protected final NumberFunction functionFor(String name) { return manager.functionFor(name); } diff --git a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 9d2952a..a6a2a1f 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -27,7 +27,7 @@ public class PluginManager { /** * The map of functions registered by the plugins. */ - private Map registeredFunctions; + private Map registeredFunctions; /** * The map of tree value functions regstered by the plugins. */ @@ -88,7 +88,7 @@ public class PluginManager { * @param name the name of the function. * @param function the function to register. */ - public void registerFunction(String name, Function function) { + public void registerFunction(String name, NumberFunction function) { registeredFunctions.put(name, function); } @@ -138,7 +138,7 @@ public class PluginManager { * @param name the name of the function. * @return the function, or null if it was not found. */ - public Function functionFor(String name) { + public NumberFunction functionFor(String name) { return registeredFunctions.get(name); } diff --git a/core/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/core/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index 1568b15..c8cee64 100755 --- a/core/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java @@ -4,9 +4,6 @@ import org.nwapw.abacus.function.*; import org.nwapw.abacus.number.NaiveNumber; import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.number.PreciseNumber; -import org.nwapw.abacus.tree.BinaryNode; -import org.nwapw.abacus.tree.Reducer; -import org.nwapw.abacus.tree.TreeNode; import java.util.ArrayList; import java.util.HashMap; @@ -231,7 +228,7 @@ public class StandardPlugin extends Plugin { /** * The absolute value function, abs(-3) = 3 */ - public static final Function FUNCTION_ABS = new Function() { + public static final NumberFunction FUNCTION_ABS = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -245,7 +242,7 @@ public class StandardPlugin extends Plugin { /** * The natural log function. */ - public static final Function FUNCTION_LN = new Function() { + public static final NumberFunction FUNCTION_LN = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1 && params[0].compareTo(fromInt(params[0].getClass(), 0)) > 0; @@ -325,7 +322,7 @@ public class StandardPlugin extends Plugin { /** * Gets a random number smaller or equal to the given number's integer value. */ - public static final Function FUNCTION_RAND_INT = new Function() { + public static final NumberFunction FUNCTION_RAND_INT = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -369,7 +366,7 @@ public class StandardPlugin extends Plugin { /** * The square root function. */ - public static final Function FUNCTION_SQRT = new Function() { + public static final NumberFunction FUNCTION_SQRT = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -384,7 +381,7 @@ public class StandardPlugin extends Plugin { /** * The exponential function, exp(1) = e^1 = 2.71... */ - public static final Function FUNCTION_EXP = new Function() { + public static final NumberFunction FUNCTION_EXP = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -421,7 +418,7 @@ public class StandardPlugin extends Plugin { /** * The sine function (the argument is interpreted in radians). */ - public final Function functionSin = new Function() { + public final NumberFunction functionSin = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -445,7 +442,7 @@ public class StandardPlugin extends Plugin { /** * The cosine function (the argument is in radians). */ - public final Function functionCos = new Function() { + public final NumberFunction functionCos = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -460,7 +457,7 @@ public class StandardPlugin extends Plugin { /** * The tangent function (the argument is in radians). */ - public final Function functionTan = new Function() { + public final NumberFunction functionTan = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -474,7 +471,7 @@ public class StandardPlugin extends Plugin { /** * The secant function (the argument is in radians). */ - public final Function functionSec = new Function() { + public final NumberFunction functionSec = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -488,7 +485,7 @@ public class StandardPlugin extends Plugin { /** * The cosecant function (the argument is in radians). */ - public final Function functionCsc = new Function() { + public final NumberFunction functionCsc = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -502,7 +499,7 @@ public class StandardPlugin extends Plugin { /** * The cotangent function (the argument is in radians). */ - public final Function functionCot = new Function() { + public final NumberFunction functionCot = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -517,7 +514,7 @@ public class StandardPlugin extends Plugin { /** * The arcsine function (return type in radians). */ - public final Function functionArcsin = new Function() { + public final NumberFunction functionArcsin = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1 @@ -550,7 +547,7 @@ public class StandardPlugin extends Plugin { /** * The arccosine function. */ - public final Function functionArccos = new Function() { + public final NumberFunction functionArccos = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) <= 0; @@ -566,7 +563,7 @@ public class StandardPlugin extends Plugin { /** * The arccosecant function. */ - public final Function functionArccsc = new Function() { + public final NumberFunction functionArccsc = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) >= 0; @@ -582,7 +579,7 @@ public class StandardPlugin extends Plugin { /** * The arcsecant function. */ - public final Function functionArcsec = new Function() { + public final NumberFunction functionArcsec = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) >= 0; @@ -598,7 +595,7 @@ public class StandardPlugin extends Plugin { /** * The arctangent function. */ - public final Function functionArctan = new Function() { + public final NumberFunction functionArctan = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; @@ -639,7 +636,7 @@ public class StandardPlugin extends Plugin { /** * The arccotangent function. Range: (0, pi). */ - public final Function functionArccot = new Function() { + public final NumberFunction functionArccot = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 1; diff --git a/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java b/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java index a62f395..ec3b6f3 100644 --- a/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java +++ b/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java @@ -1,11 +1,10 @@ package org.nwapw.abacus.tree; import org.nwapw.abacus.Abacus; -import org.nwapw.abacus.function.Function; +import org.nwapw.abacus.function.NumberFunction; import org.nwapw.abacus.function.Operator; import org.nwapw.abacus.function.TreeValueFunction; import org.nwapw.abacus.number.NumberInterface; -import org.nwapw.abacus.plugin.NumberImplementation; /** * A reducer implementation that turns a tree into a single number. @@ -47,7 +46,7 @@ public class NumberReducer implements Reducer { for (int i = 0; i < convertedChildren.length; i++) { convertedChildren[i] = (NumberInterface) children[i]; } - Function function = abacus.getPluginManager().functionFor(((FunctionNode) node).getCallTo()); + NumberFunction function = abacus.getPluginManager().functionFor(((FunctionNode) node).getCallTo()); if (function == null) return null; return function.apply(convertedChildren); } else if (node instanceof TreeValueFunctionNode){ diff --git a/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java b/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java index 014bbbb..5eaea16 100644 --- a/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java +++ b/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java @@ -18,7 +18,7 @@ public class TokenizerTests { private static Abacus abacus = new Abacus(new Configuration(0, "precise", new String[]{})); private static LexerTokenizer lexerTokenizer = new LexerTokenizer(); - private static Function subtractFunction = new Function() { + private static NumberFunction subtractFunction = new NumberFunction() { @Override protected boolean matchesParams(NumberInterface[] params) { return params.length == 2;