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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theallOutputsrecord component.final booleanIndicates whether some other object is "equal to" this one.<T> TGets an output value 获取输出值<T> TGets an output value with default 获取输出值,带默认值final inthashCode()Returns a hash code value for this object.booleanhasMatch()Checks if any row matched 检查是否有行匹配intGets the count of matched rows 获取匹配行的数量booleanmatched()Returns the value of thematchedrecord component.Returns the value of thematchedRowsrecord component.static DecisionResultCreates a result for multiple matches 创建多个匹配的结果static DecisionResultnoMatch()Creates a result for no match 创建无匹配的结果outputs()Returns the value of theoutputsrecord component.static DecisionResultsingleMatch(int rowIndex, Map<String, Object> outputs) Creates a result for a single match 创建单个匹配的结果final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
DecisionResult
public DecisionResult(boolean matched, Map<String, Object> outputs, List<Integer> matchedRows, List<Map<String, Object>> allOutputs) Creates an instance of aDecisionResultrecord class.- Parameters:
matched- the value for thematchedrecord componentoutputs- the value for theoutputsrecord componentmatchedRows- the value for thematchedRowsrecord componentallOutputs- the value for theallOutputsrecord component
-
-
Method Details
-
hasMatch
public boolean hasMatch()Checks if any row matched 检查是否有行匹配- Returns:
- true if matched | 如果匹配返回true
-
get
Gets an output value 获取输出值- Type Parameters:
T- the value type | 值类型- Parameters:
key- the output key | 输出键- Returns:
- the output value | 输出值
-
get
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
Creates a result for no match 创建无匹配的结果- Returns:
- no-match result | 无匹配结果
-
singleMatch
Creates a result for a single match 创建单个匹配的结果- Parameters:
rowIndex- the matched row index | 匹配行索引outputs- the output values | 输出值- Returns:
- the result | 结果
-
multipleMatches
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
matched
-
outputs
-
matchedRows
Returns the value of thematchedRowsrecord component.- Returns:
- the value of the
matchedRowsrecord component
-
allOutputs
Returns the value of theallOutputsrecord component.- Returns:
- the value of the
allOutputsrecord component
-