Record Class CollectionFilterNode

java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.CollectionFilterNode
Record Components:
target - the target collection node | 目标集合节点
predicate - the filter predicate | 过滤谓词
mode - the filter mode (ALL, FIRST, LAST) | 过滤模式
All Implemented Interfaces:
Node

public record CollectionFilterNode(Node target, Node predicate, CollectionFilterNode.FilterMode mode) extends Record implements Node
Collection Filter Node 集合过滤节点

Represents collection filtering: users.?[age > 18]

表示集合过滤:users.?[age > 18]

Features | 主要功能:

  • Filter all matching elements (.?[]) - 过滤所有匹配元素
  • Select first matching element (.^[]) - 选择第一个匹配元素
  • Select last matching element (.$[]) - 选择最后一个匹配元素
  • Child context with #this binding per element - 每个元素绑定#this的子上下文

Usage Examples | 使用示例:

// Filter users older than 18
Node filter = CollectionFilterNode.all(usersNode, predicateNode);
List<?> result = (List<?>) filter.evaluate(ctx);

// Get first match
Node first = CollectionFilterNode.first(usersNode, predicateNode);
Object firstMatch = first.evaluate(ctx);

Security | 安全性:

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

    • CollectionFilterNode

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

    • of

      public static CollectionFilterNode of(Node target, Node predicate)
      Create filter node (default: all matching elements) 创建过滤节点(默认:所有匹配元素)
      Parameters:
      target - the target node | 目标节点
      predicate - the predicate | 谓词
      Returns:
      the filter node | 过滤节点
    • all

      public static CollectionFilterNode all(Node target, Node predicate)
      Create filter node for all matching elements 创建选择所有匹配元素的过滤节点
      Parameters:
      target - the target node | 目标节点
      predicate - the predicate | 谓词
      Returns:
      the filter node | 过滤节点
    • first

      public static CollectionFilterNode first(Node target, Node predicate)
      Create filter node for first matching element 创建选择第一个匹配元素的过滤节点
      Parameters:
      target - the target node | 目标节点
      predicate - the predicate | 谓词
      Returns:
      the filter node | 过滤节点
    • last

      public static CollectionFilterNode last(Node target, Node predicate)
      Create filter node for last matching element 创建选择最后一个匹配元素的过滤节点
      Parameters:
      target - the target node | 目标节点
      predicate - the predicate | 谓词
      Returns:
      the filter 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
    • predicate

      public Node predicate()
      Returns the value of the predicate record component.
      Returns:
      the value of the predicate record component
    • mode

      Returns the value of the mode record component.
      Returns:
      the value of the mode record component