Class ConditionParser
java.lang.Object
org.apache.maven.internal.impl.model.profile.ConditionParser
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA functional interface that represents an expression function to be applied to a list of arguments. -
Constructor Summary
ConstructorsConstructorDescriptionConditionParser(Map<String, ConditionParser.ExpressionFunction> functions, Function<String, String> propertyResolver) Constructs a newConditionParserwith the given function mappings. -
Method Summary
Modifier and TypeMethodDescriptionParses the given expression and returns the result of the evaluation.static BooleanConverts an object to a boolean value.static doubleConverts an object to a double value.static intConverts an object to an integer value.static StringConverts an object to a string representation.
-
Constructor Details
-
ConditionParser
public ConditionParser(Map<String, ConditionParser.ExpressionFunction> functions, Function<String, String> propertyResolver) Constructs a newConditionParserwith the given function mappings.- Parameters:
functions- a map of function names to their correspondingExpressionFunctionimplementationspropertyResolver- the property resolver
-
-
Method Details
-
parse
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
Converts an object to a string representation. If the object is aDouble, it formats it without any decimal places. Otherwise, it uses theString.valueOfmethod.- Parameters:
value- the object to convert to a string- Returns:
- the string representation of the object
-
toBoolean
Converts an object to a boolean value. If the object is: - aBoolean, returns its value directly. - aString, returnstrueif the string is non-blank. - aNumber, returnstrueif its integer value is not zero. For other object types, returnstrueif the object is non-null.- Parameters:
value- the object to convert to a boolean- Returns:
- the boolean representation of the object
-
toDouble
Converts an object to a double value. If the object is: - aNumber, returns its double value. - aString, tries to parse it as a double. - aBoolean, returns1.0fortrue,0.0forfalse. If the object cannot be converted, aRuntimeExceptionis 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
Converts an object to an integer value. If the object is: - aNumber, returns its integer value. - aString, tries to parse it as an integer, or as a double then converted to an integer. - aBoolean, returns1fortrue,0forfalse. If the object cannot be converted, aRuntimeExceptionis 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
-