- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- ch.qos.logback.core.boolex.PropertyConditionBase
-
- ch.qos.logback.core.boolex.ExpressionPropertyCondition
-
- All Implemented Interfaces:
PropertyCondition,Condition,ContextAware,LifeCycle
public class ExpressionPropertyCondition extends PropertyConditionBase
This class evaluates boolean expressions based on property lookups.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
Fields Modifier and Type Field Description protected Map<String,BiFunction<String,String,Boolean>>biFunctionMapA map that associates a string key with a bi-function for evaluating boolean conditions.protected Map<String,Function<String,Boolean>>functionMapA 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
Constructors Constructor Description ExpressionPropertyCondition()Constructs an ExpressionPropertyCondition and initializes the function maps with supported unary and binary functions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanevaluate()Evaluates the parsed expression against the current property context.StringgetExpression()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, stop
-
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
-
-
-
Field Detail
-
functionMap
protected Map<String,Function<String,Boolean>> 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
protected Map<String,BiFunction<String,String,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 Detail
-
ExpressionPropertyCondition
public ExpressionPropertyCondition()
Constructs an ExpressionPropertyCondition and initializes the function maps with supported unary and binary functions.
-
-
Method Detail
-
start
public void 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
public String getExpression()
Returns the current expression string.- Returns:
- the expression, or null if not set
-
setExpression
public void setExpression(String expression)
Sets the expression to be evaluated.- Parameters:
expression- the boolean expression string
-
evaluate
public boolean 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
-
-