Package com.singularsys.jep.functions
Class UnaryFunction
- java.lang.Object
-
- com.singularsys.jep.functions.PostfixMathCommand
-
- com.singularsys.jep.functions.UnaryFunction
-
- All Implemented Interfaces:
PostfixMathCommandI
,java.io.Serializable
- Direct Known Subclasses:
Abs
,ArcCosine
,ArcCosineH
,ArcSine
,ArcSineH
,ArcTangent
,ArcTanH
,Arg
,BitComp
,Ceil
,Conjugate
,Cosecant
,Cosine
,CosineH
,Cotangent
,Exp
,Factorial
,FieldAbs
,FieldConsole.BigDecPFMC
,FieldConsole.DoublePFMC
,FieldFactorial
,FieldSignum
,FieldSqrt
,Floor
,Identity
,Imaginary
,IsInfinite
,IsNaN
,IsNull
,IsType
,JepTest.MyUnary
,Length
,LightWeightComponentSetTest.NonThreadSafeOpFunction
,Logarithm
,LogBase2
,LowerCase
,MatrixDet
,MatrixInv
,MatrixNeg
,MatrixSize
,MatrixTrace
,MatrixTrans
,MatrixZeroVec
,NaturalLogarithm
,Not
,NullWrappedUnary
,RationalRound
,Real
,Secant
,Signum
,Sine
,SineH
,SquareRoot
,Str
,StrictNaturalLogarithm
,Tangent
,TanH
,Trim
,UMinus
,UpperCase
public abstract class UnaryFunction extends PostfixMathCommand
Convenient base class for unary functions. Defines anObject eval(Object arg)
method for calculating the result.- Author:
- Richard Morris
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
-
Constructor Summary
Constructors Constructor Description UnaryFunction()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.Object
eval(java.lang.Object arg)
static <T> UnaryFunction
instanceOf(java.lang.Class<T> type, java.util.function.Function<T,? super java.lang.Object> fun)
Create a UnaryFunction from a lambda expression where the argument is of a specified type.static UnaryFunction
instanceOf(java.util.function.Function<java.lang.Object,? super java.lang.Object> fun)
Create a UnaryFunction from a lambda expression where the argument can be any Object.void
run(java.util.Stack<java.lang.Object> stack)
Callseval(Object)
-
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
-
-
-
-
Method Detail
-
run
public void run(java.util.Stack<java.lang.Object> stack) throws EvaluationException
Callseval(Object)
- Specified by:
run
in interfacePostfixMathCommandI
- Overrides:
run
in classPostfixMathCommand
- Parameters:
stack
- arguments for function- Throws:
EvaluationException
- if function cannot be evaluated
-
eval
public abstract java.lang.Object eval(java.lang.Object arg) throws EvaluationException
- Throws:
EvaluationException
-
instanceOf
public static UnaryFunction instanceOf(java.util.function.Function<java.lang.Object,? super java.lang.Object> fun)
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
public static <T> UnaryFunction instanceOf(java.lang.Class<T> type, java.util.function.Function<T,? super java.lang.Object> fun)
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
-
-