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
Modifier and TypeClassDescriptionstatic interface
A functional interface that represents an expression function to be applied to a list of arguments. -
Constructor Summary
ConstructorDescriptionConditionParser
(Map<String, ConditionParser.ExpressionFunction> functions, Function<String, String> propertyResolver) Constructs a newConditionParser
with the given function mappings. -
Method Summary
Modifier and TypeMethodDescriptionParses the given expression and returns the result of the evaluation.static Boolean
Converts an object to a boolean value.static double
Converts an object to a double value.static int
Converts an object to an integer value.static String
Converts an object to a string representation.
-
Constructor Details
-
ConditionParser
public ConditionParser(Map<String, ConditionParser.ExpressionFunction> functions, Function<String, String> propertyResolver) Constructs a newConditionParser
with the given function mappings.- Parameters:
functions
- a map of function names to their correspondingExpressionFunction
implementationspropertyResolver
- 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.valueOf
method.- 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
, returnstrue
if the string is non-blank. - aNumber
, returnstrue
if its integer value is not zero. For other object types, returnstrue
if 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.0
fortrue
,0.0
forfalse
. If the object cannot be converted, aRuntimeException
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
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
, returns1
fortrue
,0
forfalse
. If the object cannot be converted, aRuntimeException
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
-