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

Rename Function to NumberFunction.

This commit is contained in:
Danila Fedorin 2017-08-25 14:56:36 -07:00
parent d04adf4da5
commit f83f2a7aaa
6 changed files with 26 additions and 31 deletions

View File

@ -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<NumberInterface, NumberInterface> {
public abstract class NumberFunction extends Applicable<NumberInterface, NumberInterface> {
}

View File

@ -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);
}

View File

@ -27,7 +27,7 @@ public class PluginManager {
/**
* The map of functions registered by the plugins.
*/
private Map<String, Function> registeredFunctions;
private Map<String, NumberFunction> 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);
}

View File

@ -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;

View File

@ -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<NumberInterface> {
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){

View File

@ -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;