Package com.singularsys.jep.functions
Class UnaryFunction
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.UnaryFunction
- All Implemented Interfaces:
PostfixMathCommandI
,Serializable
- Direct Known Subclasses:
Abs
,ArcCosine
,ArcCosineH
,ArcSine
,ArcSineH
,ArcTangent
,ArcTanH
,Arg
,BitComp
,Ceil
,Conjugate
,Cosecant
,Cosine
,CosineH
,Cotangent
,Exp
,Factorial
,Floor
,Identity
,Imaginary
,IsInfinite
,IsNaN
,IsNull
,JepTest.MyUnary
,Length
,Logarithm
,LogBase2
,LowerCase
,NaturalLogarithm
,Not
,NullWrappedUnary
,Real
,Secant
,Signum
,Sine
,SineH
,SquareRoot
,Str
,StrictNaturalLogarithm
,Tangent
,TanH
,Trim
,UMinus
,UpperCase
Convenient base class for unary functions.
Defines an
Object eval(Object arg)
method for calculating the result.- 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 TypeMethodDescriptionabstract Object
Evaluate the functionstatic <T> UnaryFunction
instanceOf
(Class<T> type, Function<T, ? super Object> fun) Create a UnaryFunction from a lambda expression where the argument is of a specified type.static UnaryFunction
instanceOf
(Function<Object, ? super Object> fun) Create a UnaryFunction from a lambda expression where the argument can be any Object.void
Used for compatibility withStandardEvaluator
Simple callseval(Object)
placing result on stack.Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
-
Constructor Details
-
UnaryFunction
public UnaryFunction()Default constructor. Sets the function to have a single argument.
-
-
Method Details
-
run
Used for compatibility withStandardEvaluator
Simple callseval(Object)
placing result on stack.- Specified by:
run
in interfacePostfixMathCommandI
- Overrides:
run
in classPostfixMathCommand
- Parameters:
stack
- arguments for function- Throws:
EvaluationException
- if function cannot be evaluated
-
eval
Evaluate the function- Parameters:
arg
- the single argument passed in- Returns:
- the result of the function
- Throws:
EvaluationException
-
instanceOf
Create a UnaryFunction from a lambda expression where the argument can be any Object. For exampleUnaryFunction.instanceOf(x -> 1.0 / ((Number) x).doubleValue())
- Parameters:
fun
- the lambda function- Returns:
- a new UnaryFunction instance
- Since:
- Jep 4.0
-
instanceOf
Create a UnaryFunction from a lambda expression where the argument is of a specified type. For exampleUnaryFunction.instanceOf(Integer.class, x -> -x )
or using a method referenceUnaryFunction.instanceOf(Double.class,Math::cbrt)
. Theeval(Object)
method will throw anIllegalParameterException
if the 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 UnaryFunction instance
- Since:
- Jep 4.0
-