Interface Condition

All Known Implementing Classes:
CompositeCondition, PredicateCondition
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Condition
Condition Interface - Rule Condition Abstraction 条件接口 - 规则条件抽象

Represents a condition that can be evaluated against a rule context to determine if a rule should fire.

表示可以针对规则上下文评估的条件,以确定规则是否应该触发。

Features | 主要功能:

  • Context-based evaluation - 基于上下文的评估
  • Composable (AND, OR, NOT) - 可组合(AND、OR、NOT)
  • Functional interface - 函数式接口

Usage Examples | 使用示例:

// Lambda condition
Condition c1 = ctx -> ctx.get("age") > 18;

// Composite conditions
Condition c2 = c1.and(ctx -> ctx.get("verified"));
Condition c3 = c1.or(ctx -> ctx.get("admin"));
Condition c4 = c1.negate();

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: No (context must not be null) - 空值安全: 否(上下文不能为null)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static Condition
    A condition that always returns false 始终返回false的条件
    static Condition
    A condition that always returns true 始终返回true的条件
    default Condition
    and(Condition other)
    Returns a condition that is the logical AND of this and another 返回此条件与另一个条件的逻辑AND
    boolean
    Evaluates this condition against the given context 针对给定上下文评估此条件
    default Condition
    Returns a condition that is the logical negation of this 返回此条件的逻辑否定
    default Condition
    or(Condition other)
    Returns a condition that is the logical OR of this and another 返回此条件与另一个条件的逻辑OR
  • Method Details

    • evaluate

      boolean evaluate(RuleContext context)
      Evaluates this condition against the given context 针对给定上下文评估此条件
      Parameters:
      context - the rule context | 规则上下文
      Returns:
      true if the condition is satisfied | 如果条件满足返回true
    • and

      default Condition and(Condition other)
      Returns a condition that is the logical AND of this and another 返回此条件与另一个条件的逻辑AND
      Parameters:
      other - the other condition | 另一个条件
      Returns:
      the combined condition | 组合条件
    • or

      default Condition or(Condition other)
      Returns a condition that is the logical OR of this and another 返回此条件与另一个条件的逻辑OR
      Parameters:
      other - the other condition | 另一个条件
      Returns:
      the combined condition | 组合条件
    • negate

      default Condition negate()
      Returns a condition that is the logical negation of this 返回此条件的逻辑否定
      Returns:
      the negated condition | 否定条件
    • alwaysTrue

      static Condition alwaysTrue()
      A condition that always returns true 始终返回true的条件
      Returns:
      the always-true condition | 始终为true的条件
    • alwaysFalse

      static Condition alwaysFalse()
      A condition that always returns false 始终返回false的条件
      Returns:
      the always-false condition | 始终为false的条件