Class CompositeCondition

java.lang.Object
cloud.opencode.base.rules.condition.CompositeCondition
All Implemented Interfaces:
Condition

public class CompositeCondition extends Object implements Condition
Composite Condition - Combines Multiple Conditions with Logical Operators 组合条件 - 使用逻辑运算符组合多个条件

Allows combining multiple conditions using AND, OR, or NOT operators.

允许使用AND、OR或NOT运算符组合多个条件。

Features | 主要功能:

  • AND, OR, NOT logical operators - AND、OR、NOT逻辑运算符
  • Short-circuit evaluation - 短路求值
  • Factory methods for convenience - 便捷工厂方法

Usage Examples | 使用示例:

// AND combination
Condition andCondition = new CompositeCondition(
    Operator.AND, List.of(condition1, condition2)
);

// OR combination
Condition orCondition = new CompositeCondition(
    Operator.OR, List.of(condition1, condition2)
);

// NOT (single condition)
Condition notCondition = new CompositeCondition(
    Operator.NOT, List.of(condition1)
);

Security | 安全性:

  • Thread-safe: No (not synchronized) - 线程安全: 否(未同步)
  • Null-safe: No (conditions must not be null) - 空值安全: 否(条件不能为null)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • CompositeCondition

      public CompositeCondition(CompositeCondition.Operator operator, List<Condition> conditions)
      Creates a composite condition 创建组合条件
      Parameters:
      operator - the logical operator | 逻辑运算符
      conditions - the conditions to combine | 要组合的条件
  • Method Details

    • evaluate

      public boolean evaluate(RuleContext context)
      Description copied from interface: Condition
      Evaluates this condition against the given context 针对给定上下文评估此条件
      Specified by:
      evaluate in interface Condition
      Parameters:
      context - the rule context | 规则上下文
      Returns:
      true if the condition is satisfied | 如果条件满足返回true
    • getOperator

      public CompositeCondition.Operator getOperator()
      Gets the operator 获取运算符
      Returns:
      the operator | 运算符
    • getConditions

      public List<Condition> getConditions()
      Gets the conditions 获取条件列表
      Returns:
      the conditions | 条件列表
    • and

      public static CompositeCondition and(Condition... conditions)
      Creates an AND composite condition 创建AND组合条件
      Parameters:
      conditions - the conditions | 条件
      Returns:
      the composite condition | 组合条件
    • or

      public static CompositeCondition or(Condition... conditions)
      Creates an OR composite condition 创建OR组合条件
      Parameters:
      conditions - the conditions | 条件
      Returns:
      the composite condition | 组合条件
    • not

      public static CompositeCondition not(Condition condition)
      Creates a NOT composite condition 创建NOT组合条件
      Parameters:
      condition - the condition to negate | 要否定的条件
      Returns:
      the composite condition | 组合条件