Class Function

java.lang.Object
net.objecthunter.exp4j.function.Function
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
FunctionExpresion

public abstract class Function extends Object implements Serializable
A class representing a Function which can be used in an expression
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new Function with a given name that takes a single argument
    Function(String name, int numArguments)
    Create a new Function with a given name and number of arguments
    Function(String name, int numArguments, boolean deterministic)
    Create a new Function with a given name and number of arguments
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract double
    apply(double... args)
    Method that does the actual calculation of the function value given the arguments
    Get the name of the Function
    int
    Get the number of arguments for this function
    boolean
    Tells if a function is deterministic, in this scenario basically applies to functions that are not supposed to be simplified.
    static boolean
    Tells if a function name is valid in the context of the expression.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Function

      public Function(String name, int numArguments, boolean deterministic)
      Create a new Function with a given name and number of arguments
      Parameters:
      name - the name of the Function
      numArguments - the number of arguments the function takes
      deterministic - true if the function is deterministic (i.e. can be simplified) false otherwise
    • Function

      public Function(String name, int numArguments)
      Create a new Function with a given name and number of arguments
      Parameters:
      name - the name of the Function
      numArguments - the number of arguments the function takes
    • Function

      public Function(String name)
      Create a new Function with a given name that takes a single argument
      Parameters:
      name - the name of the Function
  • Method Details

    • isDeterministic

      public boolean isDeterministic()
      Tells if a function is deterministic, in this scenario basically applies to functions that are not supposed to be simplified.
      Returns:
      true if the function is to be simplified (deterministic) and false otherwise
    • getName

      public String getName()
      Get the name of the Function
      Returns:
      the name
    • getNumArguments

      public int getNumArguments()
      Get the number of arguments for this function
      Returns:
      the number of arguments
    • apply

      public abstract double apply(double... args)
      Method that does the actual calculation of the function value given the arguments
      Parameters:
      args - the set of arguments used for calculating the function
      Returns:
      the result of the function evaluation
    • isValidFunctionName

      public static boolean isValidFunctionName(String name)
      Tells if a function name is valid in the context of the expression. This means that it's not null or empty, and it only contains ASCII chars, _ or digits.
      Parameters:
      name - name to test
      Returns:
      true if the function name can be used and false otherwise