Class Expression

    • Constructor Summary

      Constructors 
      Constructor Description
      Expression​(java.lang.String expressionString, PrimitiveElement... elements)
      Constructor - creates new expression from expression string.
      Expression​(PrimitiveElement... elements)
      Default constructor - empty expression
    • Method Summary

      Modifier and Type Method Description
      void addArguments​(Argument... arguments)
      Adds arguments (variadic) to the expression definition.
      void addConstants​(java.util.List<Constant> constantsList)
      Adds constants to the expression definition.
      void addConstants​(Constant... constants)
      Adds constants (variadic parameters) to the expression definition.
      void addDefinitions​(PrimitiveElement... elements)
      Adds user defined elements (such as: Arguments, Constants, Functions) to the expressions.
      void addFunctions​(Function... functions)
      Adds functions (variadic parameters) to the expression definition.
      double calculate()
      Calculates the expression value
      boolean checkLexSyntax()
      Checks syntax of the expression string.
      boolean checkSyntax()
      Checks syntax of the expression string.
      void clearDescription()
      Clears expression description
      void clearExpressionString()
      Clears expression string
      void defineArgument​(java.lang.String argumentName, double argumentValue)
      Enables to define the argument (associated with the expression) based on the argument name and the argument value.
      void defineArguments​(java.lang.String... argumentsNames)
      Enables to define the arguments (associated with the expression) based on the given arguments names.
      void defineConstant​(java.lang.String constantName, double constantValue)
      Enables to define the constant (associated with the expression) based on the constant name and constant value.
      void defineFunction​(java.lang.String functionName, java.lang.String functionExpressionString, java.lang.String... argumentsNames)
      Enables to define the function (associated with the expression) based on the function name, function expression string and arguments names (variadic parameters).
      Argument getArgument​(int argumentIndex)
      Gets argument from the expression.
      Argument getArgument​(java.lang.String argumentName)
      Gets argument from the expression.
      int getArgumentIndex​(java.lang.String argumentName)
      Gets argument index from the expression.
      int getArgumentsNumber()
      Gets number of arguments associated with the expression.
      double getArgumentValue​(java.lang.String argumentName)
      Gets argument vale.
      double getComputingTime()
      Gets computing time.
      Constant getConstant​(int constantIndex)
      Gets constant associated with the expression.
      Constant getConstant​(java.lang.String constantName)
      Gets constant associated with the expression.
      int getConstantIndex​(java.lang.String constantName)
      Gets constant index associated with the expression.
      int getConstantsNumber()
      Gets number of constants associated with the expression.
      java.util.List<Token> getCopyOfInitialTokens()
      Tokenizes expression string and returns tokens list, including: string, type, level.
      java.lang.String getDescription()
      Gets expression description.
      java.lang.String getErrorMessage()
      Method return error message after calling checkSyntax() method or calculate().
      java.lang.String getExpressionString()
      Returns expression string
      Function getFunction​(int functionIndex)
      Gets function associated with the expression.
      Function getFunction​(java.lang.String functionName)
      Gets function associated with the expression.
      int getFunctionIndex​(java.lang.String functionName)
      Gets index of function associated with the expression.
      int getFunctionsNumber()
      Gets number of functions associated with the expression.
      java.lang.String getHelp()
      Gets help content.
      java.lang.String getHelp​(java.lang.String word)
      Searching help content.
      java.util.List<KeyWord> getKeyWords()
      Returns list of key words known to the parser
      java.util.List<KeyWord> getKeyWords​(java.lang.String query)
      Returns list of key words known to the parser
      java.lang.String[] getMissingUserDefinedArguments()
      Returns missing user defined arguments names, i.e.
      java.lang.String[] getMissingUserDefinedFunctions()
      Returns missing user defined functions names, i.e.
      java.lang.String[] getMissingUserDefinedUnits()
      Returns missing user defined units names, i.e. 2*[w] + [q] where [w] and [q] are not defined function will return [w] and [q].
      boolean getRecursiveMode()
      Gets recursive mode status
      boolean getSyntaxStatus()
      Gets syntax status of the expression.
      boolean getVerboseMode()
      Returns verbose mode status.
      void removeAllArguments()
      Removes all arguments associated with the expression.
      void removeAllConstants()
      Removes all constants associated with the expression
      void removeAllFunctions()
      Removes all functions associated with the expression.
      void removeArguments​(java.lang.String... argumentsNames)
      Removes first occurrences of the arguments associated with the expression.
      void removeArguments​(Argument... arguments)
      Removes first occurrences of the arguments associated with the expression.
      void removeConstants​(java.lang.String... constantsNames)
      Removes first occurrences of the constants associated with the expression.
      void removeConstants​(Constant... constants)
      Removes first occurrences of the constants associated with the expression
      void removeDefinitions​(PrimitiveElement... elements)
      Removes user defined elements (such as: Arguments, Constants, Functions) to the expressions.
      void removeFunctions​(java.lang.String... functionsNames)
      Removes first occurrences of the functions associated with the expression.
      void removeFunctions​(Function... functions)
      Removes first occurrences of the functions associated with the expression.
      void setArgumentValue​(java.lang.String argumentName, double argumentValue)
      Sets argument value.
      void setDescription​(java.lang.String description)
      Sets expression description.
      void setExpressionString​(java.lang.String expressionString)
      Sets (modifies expression) expression string.
      void setSilentMode()
      Disables verbose mode (default silent mode).
      void setVerboseMode()
      Enables verbose mode.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NO_SYNTAX_ERRORS

        public static final boolean NO_SYNTAX_ERRORS
        Status of the Expression syntax
        See Also:
        Constant Field Values
      • SYNTAX_ERROR_OR_STATUS_UNKNOWN

        public static final boolean SYNTAX_ERROR_OR_STATUS_UNKNOWN
        See Also:
        Constant Field Values
    • Constructor Detail

      • Expression

        public Expression​(PrimitiveElement... elements)
        Default constructor - empty expression
        Parameters:
        elements - Optional elements list (variadic - comma separated) of types: Argument, Constant, Function
        See Also:
        PrimitiveElement
      • Expression

        public Expression​(java.lang.String expressionString,
                          PrimitiveElement... elements)
        Constructor - creates new expression from expression string.
        Parameters:
        expressionString - definition of the expression
        elements - Optional elements list (variadic - comma separated) of types: Argument, Constant, Function
        See Also:
        PrimitiveElement
    • Method Detail

      • getErrorMessage

        public java.lang.String getErrorMessage()
        Method return error message after calling checkSyntax() method or calculate().
        Returns:
        Error message as string.
      • getSyntaxStatus

        public boolean getSyntaxStatus()
        Gets syntax status of the expression.
        Returns:
        true if there are no syntax errors, false when syntax error was found or syntax status is unknown
      • setExpressionString

        public void setExpressionString​(java.lang.String expressionString)
        Sets (modifies expression) expression string.
        Parameters:
        expressionString - the expression string
      • getExpressionString

        public java.lang.String getExpressionString()
        Returns expression string
        Returns:
        Expression string definition.
      • clearExpressionString

        public void clearExpressionString()
        Clears expression string
      • setDescription

        public void setDescription​(java.lang.String description)
        Sets expression description.
        Parameters:
        description - the description string
      • getDescription

        public java.lang.String getDescription()
        Gets expression description.
        Returns:
        String description.
      • clearDescription

        public void clearDescription()
        Clears expression description
      • setVerboseMode

        public void setVerboseMode()
        Enables verbose mode.
      • setSilentMode

        public void setSilentMode()
        Disables verbose mode (default silent mode).
      • getVerboseMode

        public boolean getVerboseMode()
        Returns verbose mode status.
        Returns:
        true if verbose mode is on, otherwise returns false.
      • getRecursiveMode

        public boolean getRecursiveMode()
        Gets recursive mode status
        Returns:
        true if recursive mode is enabled, otherwise returns false.
      • getComputingTime

        public double getComputingTime()
        Gets computing time.
        Returns:
        computing time in seconds.
      • addDefinitions

        public void addDefinitions​(PrimitiveElement... elements)
        Adds user defined elements (such as: Arguments, Constants, Functions) to the expressions.
        Parameters:
        elements - Elements list (variadic), where Argument, Constant, Function extend the same class PrimitiveElement
        See Also:
        PrimitiveElement
      • removeDefinitions

        public void removeDefinitions​(PrimitiveElement... elements)
        Removes user defined elements (such as: Arguments, Constants, Functions) to the expressions.
        Parameters:
        elements - Elements list (variadic), where Argument, Constant, Function extend the same class PrimitiveElement
        See Also:
        PrimitiveElement
      • addArguments

        public void addArguments​(Argument... arguments)
        Adds arguments (variadic) to the expression definition.
        Parameters:
        arguments - the arguments list (comma separated list)
        See Also:
        Argument, RecursiveArgument
      • defineArguments

        public void defineArguments​(java.lang.String... argumentsNames)
        Enables to define the arguments (associated with the expression) based on the given arguments names.
        Parameters:
        argumentsNames - the arguments names (variadic) comma separated list
        See Also:
        Argument, RecursiveArgument
      • defineArgument

        public void defineArgument​(java.lang.String argumentName,
                                   double argumentValue)
        Enables to define the argument (associated with the expression) based on the argument name and the argument value.
        Parameters:
        argumentName - the argument name
        argumentValue - the the argument value
        See Also:
        Argument, RecursiveArgument
      • getArgumentIndex

        public int getArgumentIndex​(java.lang.String argumentName)
        Gets argument index from the expression.
        Parameters:
        argumentName - the argument name
        Returns:
        The argument index if the argument name was found, otherwise returns Argument.NOT_FOUND
        See Also:
        Argument, RecursiveArgument
      • getArgument

        public Argument getArgument​(java.lang.String argumentName)
        Gets argument from the expression.
        Parameters:
        argumentName - the argument name
        Returns:
        The argument if the argument name was found, otherwise returns null.
        See Also:
        Argument, RecursiveArgument
      • getArgument

        public Argument getArgument​(int argumentIndex)
        Gets argument from the expression.
        Parameters:
        argumentIndex - the argument index
        Returns:
        Argument if the argument index is between 0 and the last available argument index (getArgumentsNumber()-1), otherwise returns null.
        See Also:
        Argument, RecursiveArgument
      • getArgumentsNumber

        public int getArgumentsNumber()
        Gets number of arguments associated with the expression.
        Returns:
        The number of arguments (int >= 0)
        See Also:
        Argument, RecursiveArgument
      • setArgumentValue

        public void setArgumentValue​(java.lang.String argumentName,
                                     double argumentValue)
        Sets argument value.
        Parameters:
        argumentName - the argument name
        argumentValue - the argument value
      • getArgumentValue

        public double getArgumentValue​(java.lang.String argumentName)
        Gets argument vale.
        Parameters:
        argumentName - the argument name
        Returns:
        Argument value if argument name was found, otherwise return Double.NaN.
      • removeArguments

        public void removeArguments​(java.lang.String... argumentsNames)
        Removes first occurrences of the arguments associated with the expression.
        Parameters:
        argumentsNames - the arguments names (variadic parameters) comma separated list
        See Also:
        Argument, RecursiveArgument
      • removeArguments

        public void removeArguments​(Argument... arguments)
        Removes first occurrences of the arguments associated with the expression.
        Parameters:
        arguments - the arguments (variadic parameters) comma separated list
        See Also:
        Argument, RecursiveArgument
      • removeAllArguments

        public void removeAllArguments()
        Removes all arguments associated with the expression.
        See Also:
        Argument, RecursiveArgument
      • addConstants

        public void addConstants​(Constant... constants)
        Adds constants (variadic parameters) to the expression definition.
        Parameters:
        constants - the constants (comma separated list)
        See Also:
        Constant
      • addConstants

        public void addConstants​(java.util.List<Constant> constantsList)
        Adds constants to the expression definition.
        Parameters:
        constantsList - the list of constants
        See Also:
        Constant
      • defineConstant

        public void defineConstant​(java.lang.String constantName,
                                   double constantValue)
        Enables to define the constant (associated with the expression) based on the constant name and constant value.
        Parameters:
        constantName - the constant name
        constantValue - the constant value
        See Also:
        Constant
      • getConstantIndex

        public int getConstantIndex​(java.lang.String constantName)
        Gets constant index associated with the expression.
        Parameters:
        constantName - the constant name
        Returns:
        Constant index if constant name was found, otherwise return Constant.NOT_FOUND.
        See Also:
        Constant
      • getConstant

        public Constant getConstant​(java.lang.String constantName)
        Gets constant associated with the expression.
        Parameters:
        constantName - the constant name
        Returns:
        Constant if constant name was found, otherwise return null.
        See Also:
        Constant
      • getConstant

        public Constant getConstant​(int constantIndex)
        Gets constant associated with the expression.
        Parameters:
        constantIndex - the constant index
        Returns:
        Constant if the constantIndex is between 0 and the last available constant index (getConstantsNumber() - 1), otherwise it returns null.
        See Also:
        Constant
      • getConstantsNumber

        public int getConstantsNumber()
        Gets number of constants associated with the expression.
        Returns:
        number of constants (int >= 0)
        See Also:
        Constant
      • removeConstants

        public void removeConstants​(java.lang.String... constantsNames)
        Removes first occurrences of the constants associated with the expression.
        Parameters:
        constantsNames - the constants names (variadic parameters) comma separated list
        See Also:
        Constant
      • removeConstants

        public void removeConstants​(Constant... constants)
        Removes first occurrences of the constants associated with the expression
        Parameters:
        constants - the constants (variadic parameters) comma separated list
        See Also:
        Constant
      • removeAllConstants

        public void removeAllConstants()
        Removes all constants associated with the expression
        See Also:
        Constant
      • addFunctions

        public void addFunctions​(Function... functions)
        Adds functions (variadic parameters) to the expression definition.
        Parameters:
        functions - the functions (variadic parameters) comma separated list
        See Also:
        Function
      • defineFunction

        public void defineFunction​(java.lang.String functionName,
                                   java.lang.String functionExpressionString,
                                   java.lang.String... argumentsNames)
        Enables to define the function (associated with the expression) based on the function name, function expression string and arguments names (variadic parameters).
        Parameters:
        functionName - the function name
        functionExpressionString - the expression string
        argumentsNames - the function arguments names (variadic parameters) comma separated list
        See Also:
        Function
      • getFunctionIndex

        public int getFunctionIndex​(java.lang.String functionName)
        Gets index of function associated with the expression.
        Parameters:
        functionName - the function name
        Returns:
        Function index if function name was found, otherwise returns Function.NOT_FOUND
        See Also:
        Function
      • getFunction

        public Function getFunction​(java.lang.String functionName)
        Gets function associated with the expression.
        Parameters:
        functionName - the function name
        Returns:
        Function if function name was found, otherwise returns null.
        See Also:
        Function
      • getFunction

        public Function getFunction​(int functionIndex)
        Gets function associated with the expression.
        Parameters:
        functionIndex - the function index
        Returns:
        Function if function index is between 0 and the last available function index (getFunctionsNumber()-1), otherwise returns null.
        See Also:
        Function
      • getFunctionsNumber

        public int getFunctionsNumber()
        Gets number of functions associated with the expression.
        Returns:
        number of functions (int >= 0)
        See Also:
        Function
      • removeFunctions

        public void removeFunctions​(java.lang.String... functionsNames)
        Removes first occurrences of the functions associated with the expression.
        Parameters:
        functionsNames - the functions names (variadic parameters) comma separated list
        See Also:
        Function
      • removeFunctions

        public void removeFunctions​(Function... functions)
        Removes first occurrences of the functions associated with the expression.
        Parameters:
        functions - the functions (variadic parameters) comma separated list.
        See Also:
        Function
      • removeAllFunctions

        public void removeAllFunctions()
        Removes all functions associated with the expression.
        See Also:
        Function
      • checkLexSyntax

        public boolean checkLexSyntax()
        Checks syntax of the expression string.
        Returns:
        true if syntax is ok
      • checkSyntax

        public boolean checkSyntax()
        Checks syntax of the expression string.
        Returns:
        true if syntax is ok
      • calculate

        public double calculate()
        Calculates the expression value
        Returns:
        The expression value if syntax was ok, otherwise returns Double.NaN.
      • getCopyOfInitialTokens

        public java.util.List<Token> getCopyOfInitialTokens()
        Tokenizes expression string and returns tokens list, including: string, type, level.
        Returns:
        Copy of initial tokens.
        See Also:
        Token, mXparser.consolePrintTokens(List)
      • getMissingUserDefinedArguments

        public java.lang.String[] getMissingUserDefinedArguments()
        Returns missing user defined arguments names, i.e. sin(x) + cos(y) where x and y are not defined function will return x and y.
        Returns:
        Array of missing user defined arguments names - distinct strings.
      • getMissingUserDefinedUnits

        public java.lang.String[] getMissingUserDefinedUnits()
        Returns missing user defined units names, i.e. 2*[w] + [q] where [w] and [q] are not defined function will return [w] and [q].
        Returns:
        Array of missing user defined units names - distinct strings.
      • getMissingUserDefinedFunctions

        public java.lang.String[] getMissingUserDefinedFunctions()
        Returns missing user defined functions names, i.e. sin(x) + fun(x,y) where fun is not defined function will return fun.
        Returns:
        Array of missing user defined functions names - distinct strings.
      • getHelp

        public java.lang.String getHelp()
        Gets help content.
        Returns:
        The help content.
      • getHelp

        public java.lang.String getHelp​(java.lang.String word)
        Searching help content.
        Parameters:
        word - searching key word
        Returns:
        The help content.
      • getKeyWords

        public java.util.List<KeyWord> getKeyWords​(java.lang.String query)
        Returns list of key words known to the parser
        Parameters:
        query - Give any string to filter list of key words against this string. User more precise syntax: str=tokenString, desc=tokenDescription, syn=TokenSyntax, sin=tokenSince, wid=wordId, tid=wordTypeId to narrow the result.
        Returns:
        List of keywords known to the parser filter against query string.
        See Also:
        KeyWord, KeyWord.wordTypeId, getHelp(String)