Class ArrayFunctionBase

  • All Implemented Interfaces:
    PostfixMathCommandI, java.io.Serializable
    Direct Known Subclasses:
    Average, ElementOf, MinMax, VSum

    public abstract class ArrayFunctionBase
    extends PostfixMathCommand
    Base class for functions that operate on arrays such as Average, MinMax, and VSum. The shared functionality such as array flattening is implemented here. In the run() method, before calling calc(), Vectors and nested Vectors are flattened so 1,[2,[3, 4]] becomes [1, 2, 3, 4] which is passed in to the calc method as a List<Object>.
    Since:
    3.4.0
    See Also:
    Serialized Form
    • Constructor Detail

      • ArrayFunctionBase

        public ArrayFunctionBase()
        Default the number of parameters to any number of params (-1).
    • Method Detail

      • addToArray

        protected void addToArray​(java.util.List<java.lang.Object> l,
                                  java.lang.Object val)
        Adds a value val to the array l. This method flattens Vectors and nested Vectors so 1,[2,[3, 4]] becomes [1, 2, 3, 4].
        Parameters:
        l - The list to which to add a.
        val - The value to be added (can be a Vector).
      • calc

        protected abstract java.lang.Object calc​(java.util.List<java.lang.Object> l)
                                          throws EvaluationException
        Abstract method for performing the array calculation.
        Parameters:
        l - The list to operate on. Note this is in reverse order of the arguments of the function.
        Returns:
        The result of the calculation.
        Throws:
        EvaluationException - if the calculation cannot be performed
      • setZeroLengthErrorBehaviour

        public void setZeroLengthErrorBehaviour​(ArrayFunctionBase.ZeroLengthErrorBehaviour zeroLengthErrorBehaviour)
        Sets how to respond to arguments with zero length arrays. Either an Exception is thrown or NaN is returned.
        Parameters:
        zeroLengthErrorBehaviour - either EXCEPTION or NAN