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

public record MapLiteralNode(List<Map.Entry<Node,Node>> entries) extends Record implements 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 Details

    • MapLiteralNode

      public MapLiteralNode(List<Map.Entry<Node,Node>> entries)
      Creates an instance of a MapLiteralNode record class.
      Parameters:
      entries - the value for the entries record component
  • Method Details

    • of

      public static MapLiteralNode of(List<Map.Entry<Node,Node>> entries)
      Create map literal node 创建 Map 字面量节点
      Parameters:
      entries - the key-value entries | 键值条目
      Returns:
      the map literal node | Map 字面量节点
    • empty

      public static MapLiteralNode empty()
      Create empty map literal node 创建空 Map 字面量节点
      Returns:
      the empty map node | 空 Map 节点
    • evaluate

      public Object evaluate(EvaluationContext context)
      Description copied from interface: Node
      Evaluate this node 求值此节点
      Specified by:
      evaluate in interface Node
      Parameters:
      context - the evaluation context | 求值上下文
      Returns:
      the evaluation result | 求值结果
    • toExpressionString

      public String toExpressionString()
      Description copied from interface: Node
      Get string representation for debugging 获取用于调试的字符串表示
      Specified by:
      toExpressionString in interface Node
      Returns:
      the string representation | 字符串表示
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • entries

      public List<Map.Entry<Node,Node>> entries()
      Returns the value of the entries record component.
      Returns:
      the value of the entries record component