Record Class ElvisNode
java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.ElvisNode
- Record Components:
value- the value expression | 值表达式defaultValue- the default value expression if value is null | 值为空时的默认值表达式
- All Implemented Interfaces:
Node
Elvis/Null-Coalescing Operation Node
Elvis/空值合并运算节点
Represents the elvis operator ?: which returns the left operand if non-null,
otherwise evaluates and returns the right operand (default value).
表示 elvis 运算符 ?:,如果左操作数非空则返回左操作数,
否则求值并返回右操作数(默认值)。
Features | 主要功能:
- Null-coalescing with lazy default evaluation - 空值合并,默认值惰性求值
- Short-circuit: default not evaluated if value is non-null - 短路求值:值非空时不求值默认值
Usage Examples | 使用示例:
// name ?: 'unknown'
Node elvis = ElvisNode.of(nameNode, defaultNode);
Object result = elvis.evaluate(ctx);
Security | 安全性:
- Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
- Null-safe: No, value and defaultValue required non-null - 空值安全: 否,值和默认值要求非空
- Since:
- JDK 25, opencode-base-expression V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedefaultValuerecord component.final booleanIndicates whether some other object is "equal to" this one.evaluate(EvaluationContext context) Evaluate this node 求值此节点final inthashCode()Returns a hash code value for this object.static ElvisNodeCreate elvis operation node 创建 elvis 运算节点Get string representation for debugging 获取用于调试的字符串表示final StringtoString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.Methods inherited from interface Node
getTypeName
-
Constructor Details
-
ElvisNode
Creates an instance of aElvisNoderecord class.- Parameters:
value- the value for thevaluerecord componentdefaultValue- the value for thedefaultValuerecord component
-
-
Method Details
-
of
-
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). -
value
-
defaultValue
Returns the value of thedefaultValuerecord component.- Returns:
- the value of the
defaultValuerecord component
-