Class NaryBinaryFunction

    • 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.
      • 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
      • instanceOf

        public static NaryBinaryFunction instanceOf​(java.util.function.BiFunction<java.lang.Object,​java.lang.Object,​? super java.lang.Object> fun)
        Create a NaryBinaryFunction from a lambda expression where arguments can be Objects. For example NaryBinaryFunction.instanceOf((x,y) -> ((Number) x).doubleValue() + ((Number) y).doubleValue())
        Parameters:
        fun - the lambda function
        Returns:
        a new NaryBinaryFunction instance
        Since:
        Jep 4.0
      • instanceOf

        public static <T> NaryBinaryFunction instanceOf​(java.lang.Class<T> type,
                                                        java.util.function.BiFunction<T,​T,​? super java.lang.Object> fun)
        Create a NaryBinaryFunction from a lambda expression where both arguments are of a specified type. For example NaryBinaryFunction.instanceOf(Integer.class, (x,y) -> x * y) The eval(Object[]) and eval(Object, Object) will throw an IllegalParameterException if any 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 NaryBinaryFunction instance
        Since:
        Jep 4.0