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`, `Clear`, `Conjugate`, `Cosecant`, `Cosine`, `CosineH`, `Cotangent`, `Count`, `Entries`, `EntriesIterable`, `Exp`, `Factorial`, `Floor`, `Identity`, `Imaginary`, `IsInfinite`, `IsNaN`, `IsNull`, `IsType`, `JepTest.MyUnary`, `Keys`, `KeysIterable`, `Length`, `Logarithm`, `LogBase2`, `LowerCase`, `ModifiedParserTest.SeqFun`, `NaturalLogarithm`, `Not`, `NullWrappedUnary`, `NullWrapTest.MyUnary`, `OverloadedUnaryFunction`, `Real`, `Secant`, `Signum`, `Sine`, `SineH`, `Size`, `SquareRoot`, `Str`, `StrictNaturalLogarithm`, `Tangent`, `TanH`, `Trim`, `UMinus`, `UpperCase`, `Values`, `ValuesIterable`

public abstract class UnaryFunction extends PostfixMathCommand
Convenient base class for unary functions. Defines an `Object eval(Object arg)` method for calculating the result.

Author:
  Richard Morris
See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `UnaryFunction.FunctionWithException<T>`
  FunctionalInterface for the `BinaryFunction.instanceOf(Class, BiFunctionWithException)` method.

- ## Field Summary

  ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `UnaryFunction()`
  Default constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract Object`
  `eval(Object arg)`
  Evaluate the function
  `static UnaryFunction`
  `instanceOf(UnaryFunction.FunctionWithException<Object> fun)`
  Create a UnaryFunction from a lambda expression where the argument can be any Object.
  `static UnaryFunction`
  `instanceOf(UnaryFunction.FunctionWithException<Object> fun, String name)`
  Create a named UnaryFunction from a lambda expression where the argument can be any Object.
  `static <T> UnaryFunction`
  `instanceOf(Class<T> type, UnaryFunction.FunctionWithException<T> fun)`
  Create a UnaryFunction from a lambda expression where the argument is of a specified type.
  `static <T> UnaryFunction`
  `instanceOf(Class<T> type, UnaryFunction.FunctionWithException<T> fun, String name)`
  Create a named UnaryFunction from a lambda expression where the argument is of a specified type.
  `void`
  `run(Stack<Object> stack)`
  Used for compatibility with `StandardEvaluator` Simple calls `eval(Object)` placing result on stack.

  ### 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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### UnaryFunction

    public UnaryFunction()
    Default constructor. Sets the function to have a single argument.

- ## Method Details

  - ### run

    public void run(Stack<Object> stack) throws EvaluationException
    Used for compatibility with `StandardEvaluator` Simple calls `eval(Object)` placing result on stack.
    Specified by:
      `run` in interface `PostfixMathCommandI`
    Overrides:
      `run` in class `PostfixMathCommand`
    Parameters:
      `stack` - arguments for function
    Throws:
      `EvaluationException` - if function cannot be evaluated

  - ### eval

    public abstract Object eval(Object arg) throws EvaluationException
    Evaluate the function
    Parameters:
      `arg` - the single argument passed in
    Returns:
      the result of the function
    Throws:
      `EvaluationException` - on error

  - ### instanceOf

    public static UnaryFunction instanceOf(UnaryFunction.FunctionWithException<Object> fun)
    Create a UnaryFunction from a lambda expression where the argument can be any Object. For example `UnaryFunction.instanceOf(x -> 1.0 / ((Number) x).doubleValue())`
    Parameters:
      `fun` - the lambda function
    Returns:
      a new UnaryFunction instance
    Since:
      Jep 4.0

  - ### instanceOf

    public static UnaryFunction instanceOf(UnaryFunction.FunctionWithException<Object> fun, String name)
    Create a named UnaryFunction from a lambda expression where the argument can be any Object. For example `UnaryFunction.instanceOf(x -> 1.0 / ((Number) x).doubleValue())`
    Parameters:
      `fun` - the lambda function
      `name` - the name of the function
    Returns:
      a new UnaryFunction instance
    Since:
      Jep 4.0

  - ### instanceOf

    public static <T> UnaryFunction instanceOf(Class<T> type, UnaryFunction.FunctionWithException<T> fun)
    Create a UnaryFunction from a lambda expression where the argument is of a specified type. For example `UnaryFunction.instanceOf(Integer.class, x -> -x )` or using a method reference `UnaryFunction.instanceOf(Double.class,Math::cbrt)`. The `eval(Object)` method will throw an `IllegalParameterException` if the argument is not of the correct type.
    Type Parameters:
      `T` - type of arguments and return value
    Parameters:
      `type` - type of the arguments
      `fun` - the lambda function
    Returns:
      a new UnaryFunction instance
    Since:
      Jep 4.0

  - ### instanceOf

    public static <T> UnaryFunction instanceOf(Class<T> type, UnaryFunction.FunctionWithException<T> fun, String name)
    Create a named UnaryFunction from a lambda expression where the argument is of a specified type. For example `UnaryFunction.instanceOf(Integer.class, x -> -x )` or using a method reference `UnaryFunction.instanceOf(Double.class,Math::cbrt)`. The `eval(Object)` method will throw an `IllegalParameterException` if the argument is not of the correct type.
    Type Parameters:
      `T` - type of arguments and return value
    Parameters:
      `type` - type of the arguments
      `fun` - the lambda function
    Returns:
      a new UnaryFunction instance
    Since:
      Jep 4.0