Record Class TernaryOpNode
java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.TernaryOpNode
- Record Components:
condition- the condition | 条件trueValue- the value if true | 真值falseValue- the value if false | 假值
- All Implemented Interfaces:
Node
public record TernaryOpNode(Node condition, Node trueValue, Node falseValue)
extends Record
implements Node
Ternary Operation Node
三元运算节点
Represents ternary conditional: condition ? trueValue : falseValue
表示三元条件运算:条件 ? 真值 : 假值
Features | 主要功能:
- Conditional evaluation with lazy branch evaluation - 条件求值,分支惰性求值
- Boolean coercion for condition values - 条件值的布尔强制转换
Usage Examples | 使用示例:
// age >= 18 ? 'adult' : 'minor'
Node ternary = TernaryOpNode.of(conditionNode, trueNode, falseNode);
Object result = ternary.evaluate(ctx);
Security | 安全性:
- Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
- Null-safe: No, condition/trueValue/falseValue required non-null - 空值安全: 否,条件/真值/假值要求非空
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTernaryOpNode(Node condition, Node trueValue, Node falseValue) Creates an instance of aTernaryOpNoderecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theconditionrecord component.final booleanIndicates whether some other object is "equal to" this one.evaluate(EvaluationContext context) Evaluate this node 求值此节点Returns the value of thefalseValuerecord component.final inthashCode()Returns a hash code value for this object.static TernaryOpNodeCreate ternary operation node 创建三元运算节点Get string representation for debugging 获取用于调试的字符串表示final StringtoString()Returns a string representation of this record class.Returns the value of thetrueValuerecord component.Methods inherited from interface Node
getTypeName
-
Constructor Details
-
TernaryOpNode
Creates an instance of aTernaryOpNoderecord class.- Parameters:
condition- the value for theconditionrecord componenttrueValue- the value for thetrueValuerecord componentfalseValue- the value for thefalseValuerecord component
-
-
Method Details
-
of
Create ternary operation node 创建三元运算节点- Parameters:
condition- the condition | 条件trueValue- the value if true | 真值falseValue- the value if false | 假值- Returns:
- the ternary operation node | 三元运算节点
-
evaluate
Description copied from interface:NodeEvaluate this node 求值此节点 -
toExpressionString
Description copied from interface:NodeGet string representation for debugging 获取用于调试的字符串表示- Specified by:
toExpressionStringin interfaceNode- Returns:
- the string representation | 字符串表示
-
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. All components in this record class are compared withObjects::equals(Object,Object). -
condition
-
trueValue
-
falseValue
Returns the value of thefalseValuerecord component.- Returns:
- the value of the
falseValuerecord component
-