Package org.apfloat.calc
Class FunctionCalculatorImpl
- java.lang.Object
-
- org.apfloat.calc.AbstractCalculatorImpl
-
- org.apfloat.calc.FunctionCalculatorImpl
-
- All Implemented Interfaces:
java.io.Serializable,CalculatorImpl
- Direct Known Subclasses:
ApfloatCalculatorImpl
public abstract class FunctionCalculatorImpl extends AbstractCalculatorImpl
Calculator implementation with function support. Provides a mapping mechanism for functions.- Version:
- 1.14.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFunctionCalculatorImpl.FixedFunctionFunction taking a fixed number of arguments.protected static interfaceFunctionCalculatorImpl.FixedFunctionHandlerHandler for FixedFunction.protected static interfaceFunctionCalculatorImpl.FunctionArbitrary function.protected static interfaceFunctionCalculatorImpl.FunctionsFunction implementations.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,FunctionCalculatorImpl.Function>functionsprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description protectedFunctionCalculatorImpl()Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private java.lang.NumberargumentOrInputPrecision(java.util.List<java.lang.Number> arguments)protected FunctionCalculatorImpl.FixedFunctionfixedFunction(java.lang.String name, int minArguments, int maxArguments, FunctionCalculatorImpl.FixedFunctionHandler handler)Factory method.protected FunctionCalculatorImpl.FixedFunctionfixedFunction(java.lang.String name, int arguments, FunctionCalculatorImpl.FixedFunctionHandler handler)Factory method.java.lang.Numberfunction(java.lang.String name, java.util.List<java.lang.Number> arguments)Arbitrary function.protected abstract FunctionCalculatorImpl.FunctionsgetFunctions(java.lang.Number x)Get the function implementations.private FunctionCalculatorImpl.FunctionsgetFunctions(java.util.List<java.lang.Number> arguments)protected abstract java.lang.Numberpromote(java.lang.Number x)Promote a number to a more specific class.protected voidsetFunction(java.lang.String name, FunctionCalculatorImpl.Function function)Define a function.-
Methods inherited from class org.apfloat.calc.AbstractCalculatorImpl
add, divide, doubleFactorial, factorial, getFormat, getInputPrecision, getVariable, mod, multiply, negate, pow, setFormat, setInputPrecision, setVariable, subtract
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apfloat.calc.CalculatorImpl
format, parseDecimal, parseInteger
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
functions
private java.util.Map<java.lang.String,FunctionCalculatorImpl.Function> functions
-
-
Method Detail
-
function
public java.lang.Number function(java.lang.String name, java.util.List<java.lang.Number> arguments) throws ParseExceptionDescription copied from interface:CalculatorImplArbitrary function.- Parameters:
name- Name of the function.arguments- Function arguments.- Returns:
- Function value.
- Throws:
ParseException- In case of invalid arguments.
-
getFunctions
private FunctionCalculatorImpl.Functions getFunctions(java.util.List<java.lang.Number> arguments)
-
argumentOrInputPrecision
private java.lang.Number argumentOrInputPrecision(java.util.List<java.lang.Number> arguments)
-
fixedFunction
protected FunctionCalculatorImpl.FixedFunction fixedFunction(java.lang.String name, int arguments, FunctionCalculatorImpl.FixedFunctionHandler handler)
Factory method.- Parameters:
name- The function's name.arguments- The number of arguments that the function takes.handler- The handler of the function.- Returns:
- The function.
-
fixedFunction
protected FunctionCalculatorImpl.FixedFunction fixedFunction(java.lang.String name, int minArguments, int maxArguments, FunctionCalculatorImpl.FixedFunctionHandler handler)
Factory method.- Parameters:
name- The function's name.minArguments- The minimum number of arguments that the function takes.maxArguments- The maximum number of arguments that the function takes.handler- The handler of the function.- Returns:
- The function.
-
setFunction
protected void setFunction(java.lang.String name, FunctionCalculatorImpl.Function function)Define a function.- Parameters:
name- The function name.function- The function.
-
getFunctions
protected abstract FunctionCalculatorImpl.Functions getFunctions(java.lang.Number x)
Get the function implementations.- Parameters:
x- The number to use as the function argument.- Returns:
- The function implementations.
-
promote
protected abstract java.lang.Number promote(java.lang.Number x)
Promote a number to a more specific class.- Parameters:
x- The argument.- Returns:
- The argument, possibly converted to a more specific subclass.
-
-