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`

public abstract class BinaryFunction extends PostfixMathCommand
Convenient base class for binary functions. Defines an `Object eval(Object l,Object r)` method for calculating the result.

Author:
  Richard Morris
See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `BinaryFunction.BiFunctionWithException<T>`
  FunctionalInterface for the `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
  `BinaryFunction()`
  Create a BinaryFunction.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract Object`
  `eval(Object l, Object r)`
  Evaluate the function
  `static BinaryFunction`
  `instanceOf(BinaryFunction.BiFunctionWithException<Object> fun)`
  Create a BinaryFunction from a lambda expression where arguments can be Objects.
  `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.
  `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.
  `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.
  `final void`
  `run(Stack<Object> stack)`
  Calls `eval(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`

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

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

- ## Constructor Details

  - ### BinaryFunction

    public BinaryFunction()
    Create a BinaryFunction.

- ## Method Details

  - ### run

    public final void run(Stack<Object> stack) throws EvaluationException
    Calls `eval(Object, Object)`
    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 l, Object r) throws EvaluationException
    Evaluate the function
    Parameters:
      `l` - lhs argument
      `r` - rhs argument
    Returns:
      the results
    Throws:
      `EvaluationException` - if the function cannot be evaluated.

  - ### instanceOf

    public static BinaryFunction instanceOf(BinaryFunction.BiFunctionWithException<Object> fun)
    Create a BinaryFunction from a lambda expression where arguments can be Objects. For example `BinaryFunction.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 example `BinaryFunction.instanceOf((x,y) -> ((Number) x).doubleValue() + ((Number) y).doubleValue())`
    Parameters:
      `fun` - the lambda function
      `name` - 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 example `BinaryFunction.instanceOf(Integer.class, (x,y) -> x * y)` The `eval(Object,Object)` method will throw an `IllegalParameterException` if either 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 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 example `BinaryFunction.instanceOf(Integer.class, (x,y) -> x * y)` The `eval(Object,Object)` method will throw an `IllegalParameterException` if either 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
      `name` - the name of the function
    Returns:
      a new BinaryFunction instance
    Since:
      Jep 4.0