Record Class CollectionProjectNode

java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.CollectionProjectNode
Record Components:
target - the target collection node | 目标集合节点
projection - the projection expression | 投影表达式
All Implemented Interfaces:
Node

public record CollectionProjectNode(Node target, Node projection) extends Record implements Node
Collection Project Node 集合投影节点

Represents collection projection: users.![name]

表示集合投影:users.![name]

Features | 主要功能:

  • Project/map a collection to extract a property from each element - 投影/映射集合以从每个元素提取属性
  • Child context with #this binding per element - 每个元素绑定#this的子上下文

Usage Examples | 使用示例:

// Extract all user names: users.![name]
Node projection = CollectionProjectNode.of(usersNode, nameNode);
List<?> names = (List<?>) projection.evaluate(ctx);

Security | 安全性:

  • Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
  • Null-safe: Yes, null target returns empty list - 空值安全: 是,null目标返回空列表
Since:
JDK 25, opencode-base-expression V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • CollectionProjectNode

      public CollectionProjectNode(Node target, Node projection)
      Creates an instance of a CollectionProjectNode record class.
      Parameters:
      target - the value for the target record component
      projection - the value for the projection record component
  • Method Details

    • of

      public static CollectionProjectNode of(Node target, Node projection)
      Create projection node 创建投影节点
      Parameters:
      target - the target node | 目标节点
      projection - the projection expression | 投影表达式
      Returns:
      the projection node | 投影节点
    • 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.
    • target

      public Node target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • projection

      public Node projection()
      Returns the value of the projection record component.
      Returns:
      the value of the projection record component