Class PredicateCondition

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

public class PredicateCondition extends Object implements Condition
Predicate Condition - Condition Based on Java Predicate 谓词条件 - 基于Java谓词的条件

Wraps a Java Predicate as a rule condition for flexible condition definition.

将Java谓词包装为规则条件,以便灵活定义条件。

Features | 主要功能:

  • Predicate-to-Condition adapter - 谓词到条件的适配器
  • Lambda-friendly API - Lambda友好的API
  • Factory method support - 工厂方法支持

Usage Examples | 使用示例:

Condition condition = new PredicateCondition(
    ctx -> ctx.<Integer>get("age") >= 18
);

Security | 安全性:

  • Thread-safe: No (depends on predicate) - 线程安全: 否(取决于谓词)
  • Null-safe: No (predicate must not be null) - 空值安全: 否(谓词不能为null)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • PredicateCondition

      public PredicateCondition(Predicate<RuleContext> predicate)
      Creates a predicate condition 创建谓词条件
      Parameters:
      predicate - the predicate | 谓词
  • 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
    • of

      public static PredicateCondition of(Predicate<RuleContext> predicate)
      Creates a predicate condition from a predicate 从谓词创建谓词条件
      Parameters:
      predicate - the predicate | 谓词
      Returns:
      the condition | 条件