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:
  • Constructor Details

    • BinaryFunction

      public BinaryFunction()
      Create a BinaryFunction.
  • Method Details

    • run

      public final void run(Stack<Object> stack) throws EvaluationException
      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

      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