Package com.singularsys.jep.functions
Class NaryBinaryFunction
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.NaryBinaryFunction
- All Implemented Interfaces:
PostfixMathCommandI
,Serializable
- Direct Known Subclasses:
Add
,Concat
,JepTest.MyNaryBinary
,Multiply
Convenient base class for n-ary functions backed by a binary operation.
Defines an
Object eval(Object l,Object r)
method for calculating the result.
The operation must be associative.- Author:
- Richard Morris
- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
checkNumberOfParameters
(int n) Checks the number of parameters of the function.final Object
Evaluate given an array of argumentsabstract Object
static <T> NaryBinaryFunction
instanceOf
(Class<T> type, BiFunction<T, T, ? super Object> fun) Create a NaryBinaryFunction from a lambda expression where both arguments are of a specified type.static NaryBinaryFunction
instanceOf
(BiFunction<Object, Object, ? super Object> fun) Create a NaryBinaryFunction from a lambda expression where arguments can be Objects.final void
Callseval(Object, Object)
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
-
Constructor Details
-
NaryBinaryFunction
public NaryBinaryFunction()
-
-
Method Details
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) Description copied from class:PostfixMathCommand
Checks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method- Specified by:
checkNumberOfParameters
in interfacePostfixMathCommandI
- Overrides:
checkNumberOfParameters
in classPostfixMathCommand
- Parameters:
n
- number of parameters function will be called with.- Returns:
- false if an illegal number of parameters is supplied, true otherwise.
-
run
Callseval(Object, Object)
- Specified by:
run
in interfacePostfixMathCommandI
- Overrides:
run
in classPostfixMathCommand
- Parameters:
stack
- arguments for function- Throws:
EvaluationException
- if function cannot be evaluated
-
eval
Evaluate given an array of arguments- Parameters:
args
- array of arguments to function, must have at least one element- Returns:
- result of function
- Throws:
EvaluationException
- if empty array
-
eval
- Throws:
EvaluationException
-
instanceOf
Create a NaryBinaryFunction from a lambda expression where arguments can be Objects. For exampleNaryBinaryFunction.instanceOf((x,y) -> ((Number) x).doubleValue() + ((Number) y).doubleValue())
- Parameters:
fun
- the lambda function- Returns:
- a new NaryBinaryFunction instance
- Since:
- Jep 4.0
-
instanceOf
Create a NaryBinaryFunction from a lambda expression where both arguments are of a specified type. For exampleNaryBinaryFunction.instanceOf(Integer.class, (x,y) -> x * y)
Theeval(Object[])
andeval(Object, Object)
will throw anIllegalParameterException
if any argument is not of the correct type.- Type Parameters:
T
- type of arguments and return value- Parameters:
type
- type of the argumentsfun
- the lambda function- Returns:
- a new NaryBinaryFunction instance
- Since:
- Jep 4.0
-