Record Class IndexAccessNode

java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.IndexAccessNode
Record Components:
target - the target object node | 目标对象节点
index - the index expression | 索引表达式
nullSafe - whether to use null-safe access | 是否使用空安全访问
All Implemented Interfaces:
Node

public record IndexAccessNode(Node target, Node index, boolean nullSafe) extends Record implements Node
Index Access Node 索引访问节点

Represents index access: list[0], array[i], map["key"]

表示索引访问:list[0], array[i], map["key"]

Features | 主要功能:

  • List and array index access - 列表和数组索引访问
  • Map key access - Map键访问
  • String charAt access - 字符串字符访问
  • Null-safe access mode (?[]) - 空安全访问模式

Usage Examples | 使用示例:

Node list = IdentifierNode.of("items");
Node index = LiteralNode.ofInt(0);
Node access = IndexAccessNode.of(list, index);
Object first = access.evaluate(ctx);

// Null-safe access
Node safe = IndexAccessNode.nullSafe(list, index);

Security | 安全性:

  • Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
  • Null-safe: Optional via nullSafe mode - 空值安全: 通过nullSafe模式可选
Since:
JDK 25, opencode-base-expression V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • IndexAccessNode

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

    • of

      public static IndexAccessNode of(Node target, Node index)
      Create standard index access 创建标准索引访问
      Parameters:
      target - the target node | 目标节点
      index - the index node | 索引节点
      Returns:
      the index access node | 索引访问节点
    • nullSafe

      public static IndexAccessNode nullSafe(Node target, Node index)
      Create null-safe index access 创建空安全索引访问
      Parameters:
      target - the target node | 目标节点
      index - the index node | 索引节点
      Returns:
      the null-safe index access 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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
    • index

      public Node index()
      Returns the value of the index record component.
      Returns:
      the value of the index record component
    • nullSafe

      public boolean nullSafe()
      Returns the value of the nullSafe record component.
      Returns:
      the value of the nullSafe record component