Package com.singularsys.jep.functions

# Class Sum

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.Sum

All Implemented Interfaces:
  `PostfixMathCommandI`, `Serializable`

public class Sum extends PostfixMathCommand
Adds it arguments `sum(1,2,3,4,5)` will be 15. Note does not expand array in its arguments so `sum([1,2],[3,4])` is `[4,6]` rather than 10.

This class serves mainly as an example of a function that accepts any number of parameters. Note that the numberOfParameters is initialized to -1.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Add`
  `addFun`
  Function used to add pairs of items.

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

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Sum()`
  Constructor, using the standard `Add` function.
  `Sum(Add addFun)`
  Constructor using a specific implementation.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `checkNumberOfParameters(int n)`
  Must have one or more parameter
  `void`
  `run(Stack<Object> stack)`
  Calculates the result of summing up all parameters.

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

  `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, 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`

- ## Field Details

  - ### addFun

    protected final Add addFun
    Function used to add pairs of items.

- ## Constructor Details

  - ### Sum

    public Sum()
    Constructor, using the standard `Add` function.

  - ### Sum

    public Sum(Add addFun)
    Constructor using a specific implementation.

- ## Method Details

  - ### checkNumberOfParameters

    public boolean checkNumberOfParameters(int n)
    Must have one or more parameter
    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 void run(Stack<Object> stack) throws EvaluationException
    Calculates the result of summing up all parameters.
    Specified by:
      `run` in interface `PostfixMathCommandI`
    Overrides:
      `run` in class `PostfixMathCommand`
    Parameters:
      `stack` - arguments for function
    Throws:
      `EvaluationException` - if function cannot be evaluated