Class ExpressionParser


  • public class ExpressionParser
    extends java.lang.Object
    This class consists exclusively of static methods that operate on an expression represented as JSON Arrays.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String interpolate​(java.lang.String expr, java.util.Map<java.lang.String,​java.lang.String> data)
      Interpolate/replace values of dollar-curly-brace-wrapped variables into a string.
      static boolean isValidOperator​(java.lang.String operator)
      Check if an operator is supported by the expression parser.
      static java.lang.Object parseExpression​(java.lang.String expr)
      Execute an expression provided as a JSON array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isValidOperator

        public static boolean isValidOperator​(java.lang.String operator)
        Check if an operator is supported by the expression parser.
        Parameters:
        operator - The operator
        Returns:
        True if the operator is supported
      • interpolate

        public static java.lang.String interpolate​(java.lang.String expr,
                                                   java.util.Map<java.lang.String,​java.lang.String> data)
        Interpolate/replace values of dollar-curly-brace-wrapped variables into a string.
        Parameters:
        expr - The string where variables are to be replaced. Eg: "Hello, ${name}"
        data - The map of variable-value pairs
        Returns:
        The interpolated string with the variables replaced
      • parseExpression

        public static java.lang.Object parseExpression​(java.lang.String expr)
                                                throws org.json.JSONException
        Execute an expression provided as a JSON array. The first element is always an operator/function. The remaining elements of the array are the operands/parameters or another nested expression as a JSON array.
        Parameters:
        expr - The expression to execute.
        Returns:
        The calculated value of the expression
        Throws:
        java.lang.IllegalArgumentException - If `expr` is not a valid JSON Array
        org.json.JSONException