com.singularsys.jep.functions

## Class NaryBinaryFunction

- java.lang.Object
- - com.singularsys.jep.functions.PostfixMathCommand
  - - com.singularsys.jep.functions.NaryBinaryFunction

- All Implemented Interfaces:
    PostfixMathCommandI, java.io.Serializable
  Direct Known Subclasses:
    Add, Concat, Multiply

      public abstract class NaryBinaryFunction
      extends PostfixMathCommand

  Convenient base class for n-ary functions backed by a binary operation. Defines an `Object eval(Object l,Object r)` method for calculating the result. The operation must be associative.
  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 and Description
    `NaryBinaryFunction()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `checkNumberOfParameters(int n)` Checks the number of parameters of the function.
    `java.lang.Object` | `eval(java.lang.Object[] args)` Evaluate given an array of arguments
    `abstract java.lang.Object` | `eval(java.lang.Object l, java.lang.Object r)`
    `void` | `run(java.util.Stack<java.lang.Object> stack)` Calls `eval(Object, Object)`

    - ### Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand

      `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString`

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

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

- - ### Constructor Detail

    - #### NaryBinaryFunction

          public NaryBinaryFunction()

  - ### Method Detail

    - #### checkNumberOfParameters

          public boolean checkNumberOfParameters(int n)

      Description copied from class: `PostfixMathCommand`
      Checks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method
      Specified by:
        `checkNumberOfParameters` in interface `PostfixMathCommandI`
      Overrides:
        `checkNumberOfParameters` in class `PostfixMathCommand`
      Parameters:
        `n` - number of parameters function will be called with.
      Returns:
        false if an illegal number of parameters is supplied, true otherwise.

    - #### run

          public final void run(java.util.Stack<java.lang.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 final java.lang.Object eval(java.lang.Object[] args)
                                      throws EvaluationException

      Evaluate given an array of arguments
      Parameters:
        `args` - array of arguments to function, must have at least one element
      Returns:
        result of function
      Throws:
        `EvaluationException` - if empty array

    - #### eval

          public abstract java.lang.Object eval(java.lang.Object l,
                                                java.lang.Object r)
                                         throws EvaluationException

      Throws:
        `EvaluationException`

Copyright © 2018 Singular Systems http://www.singularsys.com/jep