Package com.singularsys.jep.functions
Class BinaryFunction
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.BinaryFunction
- All Implemented Interfaces:
PostfixMathCommandI,Serializable
- Direct Known Subclasses:
ArcTangent2,BigDecRoundSigFig,Binomial,BitAnd,BitOr,BitXor,Comparative,ComplexPFMC,ContainsKey,Cross,Divide,Dot,Get,JepTest.MyBinary,Left,Logical,LogTwoArg,LShift,Modulus,NullWrappedBinary,NullWrapTest.MyBinary,OverloadedBinaryFunction,Polar,Power,Range,Remainder,Remove,Right,RShift,Subtract,URShift
Convenient base class for binary functions.
Defines an
Object eval(Object l,Object r) method for calculating the result.- Author:
- Richard Morris
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctionalInterface for theinstanceOf(Class, BiFunctionWithException)method. -
Field Summary
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, description, name, NaN, numberOfParameters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ObjectEvaluate the functionstatic BinaryFunctionCreate a BinaryFunction from a lambda expression where arguments can be Objects.static BinaryFunctioninstanceOf(BinaryFunction.BiFunctionWithException<Object> fun, String name) Create a BinaryFunction with a given name from a lambda expression where arguments can be Objects.static <T> BinaryFunctioninstanceOf(Class<T> type, BinaryFunction.BiFunctionWithException<T> fun) Create a BinaryFunction from a lambda expression where both arguments are of a specified type.static <T> BinaryFunctioninstanceOf(Class<T> type, BinaryFunction.BiFunctionWithException<T> fun, String name) Create a BinaryFunction from a lambda expression where both arguments are of a specified type.final voidCallseval(Object, Object)Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, checkNumberOfParameters, getDescription, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toString
-
Constructor Details
-
BinaryFunction
public BinaryFunction()Create a BinaryFunction.
-
-
Method Details
-
run
Callseval(Object, Object)- Specified by:
runin interfacePostfixMathCommandI- Overrides:
runin classPostfixMathCommand- Parameters:
stack- arguments for function- Throws:
EvaluationException- if function cannot be evaluated
-
eval
Evaluate the function- Parameters:
l- lhs argumentr- rhs argument- Returns:
- the results
- Throws:
EvaluationException- if the function cannot be evaluated.
-
instanceOf
Create a BinaryFunction from a lambda expression where arguments can be Objects. For exampleBinaryFunction.instanceOf((x,y) -> ((Number) x).doubleValue() + ((Number) y).doubleValue())- Parameters:
fun- the lambda function- Returns:
- a new BinaryFunction instance
- Since:
- Jep 4.0
-
instanceOf
public static BinaryFunction instanceOf(BinaryFunction.BiFunctionWithException<Object> fun, String name) Create a BinaryFunction with a given name from a lambda expression where arguments can be Objects. For exampleBinaryFunction.instanceOf((x,y) -> ((Number) x).doubleValue() + ((Number) y).doubleValue())- Parameters:
fun- the lambda functionname- the name of the function- Returns:
- a new BinaryFunction instance
- Since:
- Jep 4.0
-
instanceOf
public static <T> BinaryFunction instanceOf(Class<T> type, BinaryFunction.BiFunctionWithException<T> fun) Create a BinaryFunction from a lambda expression where both arguments are of a specified type. For exampleBinaryFunction.instanceOf(Integer.class, (x,y) -> x * y)Theeval(Object,Object)method will throw anIllegalParameterExceptionif either 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 BinaryFunction instance
- Since:
- Jep 4.0
-
instanceOf
public static <T> BinaryFunction instanceOf(Class<T> type, BinaryFunction.BiFunctionWithException<T> fun, String name) Create a BinaryFunction from a lambda expression where both arguments are of a specified type. For exampleBinaryFunction.instanceOf(Integer.class, (x,y) -> x * y)Theeval(Object,Object)method will throw anIllegalParameterExceptionif either argument is not of the correct type.- Type Parameters:
T- type of arguments and return value- Parameters:
type- type of the argumentsfun- the lambda functionname- the name of the function- Returns:
- a new BinaryFunction instance
- Since:
- Jep 4.0
-