Class ConditionParser

java.lang.Object
org.apache.maven.internal.impl.model.profile.ConditionParser

public class ConditionParser extends Object
The ConditionParser class is responsible for parsing and evaluating expressions. It supports tokenizing the input expression and resolving custom functions passed in a map. This class implements a recursive descent parser to handle various operations including arithmetic, logical, and comparison operations, as well as function calls.
  • Constructor Details

    • ConditionParser

      public ConditionParser(Map<String,ConditionParser.ExpressionFunction> functions, Function<String,String> propertyResolver)
      Constructs a new ConditionParser with the given function mappings.
      Parameters:
      functions - a map of function names to their corresponding ExpressionFunction implementations
      propertyResolver - the property resolver
  • Method Details

    • parse

      public Object parse(String expression)
      Parses the given expression and returns the result of the evaluation.
      Parameters:
      expression - the expression to be parsed
      Returns:
      the result of parsing and evaluating the expression
    • toString

      public static String toString(Object value)
      Converts an object to a string representation. If the object is a Double, it formats it without any decimal places. Otherwise, it uses the String.valueOf method.
      Parameters:
      value - the object to convert to a string
      Returns:
      the string representation of the object
    • toBoolean

      public static Boolean toBoolean(Object value)
      Converts an object to a boolean value. If the object is: - a Boolean, returns its value directly. - a String, returns true if the string is non-blank. - a Number, returns true if its integer value is not zero. For other object types, returns true if the object is non-null.
      Parameters:
      value - the object to convert to a boolean
      Returns:
      the boolean representation of the object
    • toDouble

      public static double toDouble(Object value)
      Converts an object to a double value. If the object is: - a Number, returns its double value. - a String, tries to parse it as a double. - a Boolean, returns 1.0 for true, 0.0 for false. If the object cannot be converted, a RuntimeException is thrown.
      Parameters:
      value - the object to convert to a double
      Returns:
      the double representation of the object
      Throws:
      RuntimeException - if the object cannot be converted to a double
    • toInt

      public static int toInt(Object value)
      Converts an object to an integer value. If the object is: - a Number, returns its integer value. - a String, tries to parse it as an integer, or as a double then converted to an integer. - a Boolean, returns 1 for true, 0 for false. If the object cannot be converted, a RuntimeException is thrown.
      Parameters:
      value - the object to convert to an integer
      Returns:
      the integer representation of the object
      Throws:
      RuntimeException - if the object cannot be converted to an integer