Class ExpressionPropertyCondition
- All Implemented Interfaces:
PropertyCondition,Condition,ContextAware,LifeCycle
It supports logical operators (NOT, AND, OR) and functions like isNull, isDefined, propertyEquals, and propertyContains. Expressions are parsed using the Shunting-Yard algorithm into Reverse Polish Notation (RPN) for evaluation.
Example expression: isDefined("key1") && propertyEquals("key2", "value")
Properties are resolved via PropertyConditionBase.property(String).
- Since:
- 1.5.24
-
Field Summary
FieldsModifier and TypeFieldDescriptionA map that associates a string key with a bi-function for evaluating boolean conditions.A map that associates a string key with a function for evaluating boolean conditions.Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an ExpressionPropertyCondition and initializes the function maps with supported unary and binary functions. -
Method Summary
Modifier and TypeMethodDescriptionbooleanevaluate()Evaluates the parsed expression against the current property context.Returns the current expression string.voidsetExpression(String expression) Sets the expression to be evaluated.voidstart()Starts the condition by parsing the expression into tokens and converting them to Reverse Polish Notation (RPN) for evaluation.Methods inherited from class ch.qos.logback.core.boolex.PropertyConditionBase
getLocalPropertyContainer, isDefined, isNull, isStarted, p, property, propertyContains, propertyEquals, setLocalPropertyContainer, stopMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
functionMap
A map that associates a string key with a function for evaluating boolean conditions.This map defines the known functions. It can be overridden by subclasses to define new functions.
In the context of this class, a function is a function that takes a String argument and returns a boolean.
-
biFunctionMap
A map that associates a string key with a bi-function for evaluating boolean conditions.This map defines the known bi-functions. It can be overridden by subclasses to define new bi-functions.
In the context of this class, a bi-function is a function that takes two String arguments and returns a boolean.
-
-
Constructor Details
-
ExpressionPropertyCondition
public ExpressionPropertyCondition()Constructs an ExpressionPropertyCondition and initializes the function maps with supported unary and binary functions.
-
-
Method Details
-
start
Starts the condition by parsing the expression into tokens and converting them to Reverse Polish Notation (RPN) for evaluation.In case of malformed expression, the instance will not enter the "started" state.
- Specified by:
startin interfaceLifeCycle- Overrides:
startin classPropertyConditionBase
-
getExpression
Returns the current expression string.- Returns:
- the expression, or null if not set
-
setExpression
Sets the expression to be evaluated.- Parameters:
expression- the boolean expression string
-
evaluate
Evaluates the parsed expression against the current property context.If the instance is not in started state, returns false.
- Returns:
- true if the expression evaluates to true, false otherwise
-