Record Class RuleResult

java.lang.Object
java.lang.Record
cloud.opencode.base.rules.RuleResult
Record Components:
success - whether execution was successful | 执行是否成功
firedRules - list of fired rule names | 已触发的规则名称列表
skippedRules - list of skipped rule names | 已跳过的规则名称列表
failedRules - list of failed rule names | 已失败的规则名称列表
results - map of execution results | 执行结果Map
executionTime - total execution time | 总执行时间
errors - list of errors | 错误列表

public record RuleResult(boolean success, List<String> firedRules, List<String> skippedRules, List<String> failedRules, Map<String,Object> results, Duration executionTime, List<RuleResult.RuleError> errors) extends Record
Rule Result - Immutable Record of Rule Execution Outcome 规则结果 - 规则执行结果的不可变记录

Contains information about which rules were fired, skipped, or failed, along with execution results and timing information.

包含哪些规则被触发、跳过或失败的信息,以及执行结果和时间信息。

Features | 主要功能:

  • Fired rules tracking - 已触发规则跟踪
  • Skipped rules tracking - 已跳过规则跟踪
  • Failed rules with errors - 失败规则及错误
  • Execution results collection - 执行结果收集
  • Execution time measurement - 执行时间测量

Usage Examples | 使用示例:

RuleResult result = engine.fire(context);

if (result.success()) {
    System.out.println("Fired: " + result.firedCount());
    Double discount = result.getResult("discount");
}

if (result.wasFired("VIP-discount")) {
    // handle VIP discount
}

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

  • Method Details

    • firedCount

      public int firedCount()
      Gets the count of fired rules 获取已触发规则的数量
      Returns:
      fired rule count | 已触发规则数量
    • skippedCount

      public int skippedCount()
      Gets the count of skipped rules 获取已跳过规则的数量
      Returns:
      skipped rule count | 已跳过规则数量
    • failedCount

      public int failedCount()
      Gets the count of failed rules 获取已失败规则的数量
      Returns:
      failed rule count | 已失败规则数量
    • hasFired

      public boolean hasFired()
      Checks if any rules were fired 检查是否有规则被触发
      Returns:
      true if at least one rule was fired | 如果至少有一个规则被触发返回true
    • wasFired

      public boolean wasFired(String ruleName)
      Checks if a specific rule was fired 检查特定规则是否被触发
      Parameters:
      ruleName - the rule name | 规则名称
      Returns:
      true if the rule was fired | 如果规则被触发返回true
    • wasSkipped

      public boolean wasSkipped(String ruleName)
      Checks if a specific rule was skipped 检查特定规则是否被跳过
      Parameters:
      ruleName - the rule name | 规则名称
      Returns:
      true if the rule was skipped | 如果规则被跳过返回true
    • hasFailed

      public boolean hasFailed(String ruleName)
      Checks if a specific rule failed 检查特定规则是否失败
      Parameters:
      ruleName - the rule name | 规则名称
      Returns:
      true if the rule failed | 如果规则失败返回true
    • getResult

      public <T> T getResult(String key)
      Gets a result value by key 按键获取结果值
      Type Parameters:
      T - the result type | 结果类型
      Parameters:
      key - the result key | 结果键
      Returns:
      the result value, or null if not found | 结果值,如果未找到则为null
    • getResult

      public <T> T getResult(String key, T defaultValue)
      Gets a result value with default 获取结果值,带默认值
      Type Parameters:
      T - the result type | 结果类型
      Parameters:
      key - the result key | 结果键
      defaultValue - the default value | 默认值
      Returns:
      the result value or default | 结果值或默认值
    • hasResult

      public boolean hasResult(String key)
      Checks if a result exists 检查结果是否存在
      Parameters:
      key - the result key | 结果键
      Returns:
      true if exists | 如果存在返回true
    • successBuilder

      public static RuleResult.Builder successBuilder()
      Creates a success result builder 创建成功结果构建器
      Returns:
      builder instance | 构建器实例
    • failure

      public static RuleResult.Builder failure()
      Creates a failure result builder 创建失败结果构建器
      Returns:
      builder instance | 构建器实例
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • success

      public boolean success()
      Returns the value of the success record component.
      Returns:
      the value of the success record component
    • firedRules

      public List<String> firedRules()
      Returns the value of the firedRules record component.
      Returns:
      the value of the firedRules record component
    • skippedRules

      public List<String> skippedRules()
      Returns the value of the skippedRules record component.
      Returns:
      the value of the skippedRules record component
    • failedRules

      public List<String> failedRules()
      Returns the value of the failedRules record component.
      Returns:
      the value of the failedRules record component
    • results

      public Map<String,Object> results()
      Returns the value of the results record component.
      Returns:
      the value of the results record component
    • executionTime

      public Duration executionTime()
      Returns the value of the executionTime record component.
      Returns:
      the value of the executionTime record component
    • errors

      public List<RuleResult.RuleError> errors()
      Returns the value of the errors record component.
      Returns:
      the value of the errors record component