Class FunctionExpresion

java.lang.Object
net.objecthunter.exp4j.function.Function
net.objecthunter.exp4j.extras.FunctionExpresion
All Implemented Interfaces:
Serializable

public class FunctionExpresion extends Function
This class contains a wrapper that allows creating expression based functions.

Note: This class might will fail in threaded evaluations, if you need to use this to evaluate operations concurrently, please create a new instance per thread.This is particularly important when using Expression.copy() because Functions are not copied.

Built expressions are simplified by default

Since:
0.8-riddler
Author:
Federico Vera <[email protected]>
See Also:
  • Constructor Details

    • FunctionExpresion

      public FunctionExpresion(String name, int nargs, String expr)
      Constructor of a deterministic Expression based Function.

      The arguments will be called 'a', 'b', 'c', 'd', ..., 'z'

      Parameters:
      name - Name of the function
      nargs - Number of arguments
      expr - Expression to evaluate
      Throws:
      IllegalArgumentException - If nargs is bigger than 26
    • FunctionExpresion

      public FunctionExpresion(String name, int nargs, String expr, Function[] functions)
      Constructor of a deterministic Expression based Function.

      The arguments will be called 'a', 'b', 'c', 'd', ..., 'z'

      Parameters:
      name - Name of the function
      nargs - Number of arguments
      expr - Expression to evaluate
      functions - Additional functions needed to compile this expression
      Throws:
      IllegalArgumentException - If nargs is bigger than 26
    • FunctionExpresion

      public FunctionExpresion(String name, int nargs, boolean det, String expr, Function[] functions, Operator[] operators)
      Constructor.

      The arguments will be called 'a', 'b', 'c', 'd', ..., 'z'

      Parameters:
      name - Name of the function
      nargs - Number of arguments
      det - Tells if the function is deterministic or not
      expr - Expression to evaluate
      operators - Additional operators needed to compile this expression
      functions - Additional functions needed to compile this expression
      Throws:
      IllegalArgumentException - If nargs is bigger than 26
  • Method Details

    • apply

      public double apply(double... args)
      Description copied from class: Function
      Method that does the actual calculation of the function value given the arguments
      Specified by:
      apply in class Function
      Parameters:
      args - the set of arguments used for calculating the function
      Returns:
      the result of the function evaluation