Class FunctionParser


  • public class FunctionParser
    extends Object
    Utility class to parse string representations of functions with arguments.
    Author:
    carcassi
    • Constructor Detail

      • FunctionParser

        public FunctionParser()
    • Method Detail

      • parseFunctionWithScalarOrArrayArguments

        public static List<Object> parseFunctionWithScalarOrArrayArguments​(String string,
                                                                           String errorMessage)
        Parse a function that accepts a scalar value (number or string) or an array value (number or string).
        Parameters:
        string - the string to be parsed
        errorMessage - the error message
        Returns:
        the name of the function and the argument
      • parseFunctionWithScalarOrArrayArguments

        public static List<Object> parseFunctionWithScalarOrArrayArguments​(String nameRegex,
                                                                           String string,
                                                                           String errorMessage)
        Parse a function that accepts a scalar value (number or string) or an array value (number or string).
        Parameters:
        nameRegex - regex for function name
        string - the string to be parsed
        errorMessage - the error message for the exception if parsing fails
        Returns:
        the name of the function and the argument
      • asScalarOrList

        public static Object asScalarOrList​(List<Object> objects)
        Converts the list of arguments into a scalar or an appropriate list. Returns null if it's not possible.
        Parameters:
        objects - the argument list
        Returns:
        the value converted or null
      • asListDouble

        public static ListDouble asListDouble​(List<Object> objects)
        Convert the list of arguments to a ListDouble. Returns null if it's not possible.
        Parameters:
        objects - a list of arguments
        Returns:
        the converted list or null
      • asListString

        public static List<String> asListString​(List<Object> objects)
        Convert the list of arguments to a List. Returns null if it's not possible.
        Parameters:
        objects - a list of arguments
        Returns:
        the converted list of null
      • parseFunctionAnyParameter

        public static List<Object> parseFunctionAnyParameter​(String string)
        Parses the string and returns the name of the function plus the list of arguments. The arguments can either be doubles or Strings. Returns null if parsing fails.
        Parameters:
        string - the string to be parsed
        Returns:
        the function name and arguments; null if parsing fails
      • parseFunctionAnyParameter

        public static List<Object> parseFunctionAnyParameter​(String nameRegex,
                                                             String string)
        Parses the string and returns the name of the function plus the list of arguments. The arguments can either be doubles or Strings. Returns null if parsing fails.
        Parameters:
        nameRegex - the syntax for the function name
        string - the string to be parsed
        Returns:
        the function name and arguments; null if parsing fails