Record Class DecisionResult

java.lang.Object
java.lang.Record
cloud.opencode.base.rules.decision.DecisionResult
Record Components:
matched - whether any row matched | 是否有行匹配
outputs - the output values from the matched row(s) | 匹配行的输出值
matchedRows - the indices of matched rows | 匹配行的索引
allOutputs - all outputs when multiple rows match (for COLLECT policy) | 多行匹配时的所有输出(用于COLLECT策略)

public record DecisionResult(boolean matched, Map<String,Object> outputs, List<Integer> matchedRows, List<Map<String,Object>> allOutputs) extends Record
Decision Result - Result of Decision Table Evaluation 决策结果 - 决策表评估的结果

Contains the output values from matched rows in a decision table.

包含决策表中匹配行的输出值。

Features | 主要功能:

  • Immutable result record - 不可变结果记录
  • Single and multiple match support - 单个和多个匹配支持
  • Typed value retrieval with defaults - 类型化值检索(带默认值)

Usage Examples | 使用示例:

DecisionResult result = table.evaluate(context);
if (result.hasMatch()) {
    Double discount = result.get("discount");
    Boolean freeShipping = result.get("freeShipping");
}

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: No (outputs map must not be null) - 空值安全: 否(输出映射不能为null)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DecisionResult

      public DecisionResult(boolean matched, Map<String,Object> outputs, List<Integer> matchedRows, List<Map<String,Object>> allOutputs)
      Creates an instance of a DecisionResult record class.
      Parameters:
      matched - the value for the matched record component
      outputs - the value for the outputs record component
      matchedRows - the value for the matchedRows record component
      allOutputs - the value for the allOutputs record component
  • Method Details

    • hasMatch

      public boolean hasMatch()
      Checks if any row matched 检查是否有行匹配
      Returns:
      true if matched | 如果匹配返回true
    • get

      public <T> T get(String key)
      Gets an output value 获取输出值
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      key - the output key | 输出键
      Returns:
      the output value | 输出值
    • get

      public <T> T get(String key, T defaultValue)
      Gets an output value with default 获取输出值,带默认值
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      key - the output key | 输出键
      defaultValue - the default value | 默认值
      Returns:
      the output value or default | 输出值或默认值
    • matchCount

      public int matchCount()
      Gets the count of matched rows 获取匹配行的数量
      Returns:
      matched row count | 匹配行数量
    • noMatch

      public static DecisionResult noMatch()
      Creates a result for no match 创建无匹配的结果
      Returns:
      no-match result | 无匹配结果
    • singleMatch

      public static DecisionResult singleMatch(int rowIndex, Map<String,Object> outputs)
      Creates a result for a single match 创建单个匹配的结果
      Parameters:
      rowIndex - the matched row index | 匹配行索引
      outputs - the output values | 输出值
      Returns:
      the result | 结果
    • multipleMatches

      public static DecisionResult multipleMatches(List<Integer> matchedRows, List<Map<String,Object>> allOutputs)
      Creates a result for multiple matches 创建多个匹配的结果
      Parameters:
      matchedRows - the matched row indices | 匹配行索引
      allOutputs - all output values | 所有输出值
      Returns:
      the result | 结果
    • 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.
    • matched

      public boolean matched()
      Returns the value of the matched record component.
      Returns:
      the value of the matched record component
    • outputs

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

      public List<Integer> matchedRows()
      Returns the value of the matchedRows record component.
      Returns:
      the value of the matchedRows record component
    • allOutputs

      public List<Map<String,Object>> allOutputs()
      Returns the value of the allOutputs record component.
      Returns:
      the value of the allOutputs record component