Record Class MapLiteralNode
java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.MapLiteralNode
- Record Components:
entries- the key-value pair list | 键值对列表
- All Implemented Interfaces:
Node
Map Literal Node
Map 字面量节点
Represents a map literal like #{key: value, key2: value2}.
Both keys and values are expression nodes that are evaluated at runtime.
表示 Map 字面量,如 #{key: value, key2: value2}。
键和值都是在运行时求值的表达式节点。
Features | 主要功能:
- Inline map construction in expressions - 表达式中的内联 Map 构造
- Preserves insertion order using LinkedHashMap - 使用 LinkedHashMap 保持插入顺序
- Support nested expressions as keys and values - 支持嵌套表达式作为键和值
- Empty map creation - 空 Map 创建
Usage Examples | 使用示例:
Node map = MapLiteralNode.of(List.of(
Map.entry(LiteralNode.ofString("name"), LiteralNode.ofString("John")),
Map.entry(LiteralNode.ofString("age"), LiteralNode.ofInt(30))
));
Map<?, ?> result = (Map<?, ?>) map.evaluate(ctx);
// {"name": "John", "age": 30}
Security | 安全性:
- Thread-safe: Yes, immutable record with defensive copy - 线程安全: 是,不可变记录,防御性拷贝
- Null-safe: No, null entries list rejected - 空值安全: 否,null 条目列表被拒绝
- Since:
- JDK 25, opencode-base-expression V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMapLiteralNode(List<Map.Entry<Node, Node>> entries) Creates an instance of aMapLiteralNoderecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic MapLiteralNodeempty()Create empty map literal node 创建空 Map 字面量节点entries()Returns the value of theentriesrecord 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 MapLiteralNodeCreate map literal node 创建 Map 字面量节点Get string representation for debugging 获取用于调试的字符串表示final StringtoString()Returns a string representation of this record class.Methods inherited from interface Node
getTypeName
-
Constructor Details
-
MapLiteralNode
-
-
Method Details
-
of
Create map literal node 创建 Map 字面量节点- Parameters:
entries- the key-value entries | 键值条目- Returns:
- the map literal node | Map 字面量节点
-
empty
Create empty map literal node 创建空 Map 字面量节点- Returns:
- the empty map node | 空 Map 节点
-
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). -
entries
-