Record Class PersistentList.Cons<E>

java.lang.Object
java.lang.Record
cloud.opencode.base.collections.immutable.PersistentList.Cons<E>
Type Parameters:
E - element type | 元素类型
Record Components:
head - the first element | 第一个元素
tail - the rest of the list | 列表的其余部分
size - the number of elements | 元素数量
All Implemented Interfaces:
PersistentList<E>
Enclosing interface:
PersistentList<E>

public static record PersistentList.Cons<E>(E head, PersistentList<E> tail, int size) extends Record implements PersistentList<E>
Cons - A non-empty persistent list node (head + tail). Cons - 非空持久化列表节点(头部 + 尾部)。
Since:
JDK 25, opencode-base-collections V1.0.3
Author:
Leon Soo www.LeonSoo.com
  • Constructor Details

    • Cons

      public Cons(E head, PersistentList<E> tail, int size)
      Canonical constructor with validation. 带验证的规范构造方法。
  • Method Details

    • prepend

      public PersistentList<E> prepend(E element)
      Description copied from interface: PersistentList
      Prepend an element to the front of this list (O(1)). 在列表前端插入一个元素 (O(1))。
      Specified by:
      prepend in interface PersistentList<E>
      Parameters:
      element - the element to prepend | 要前插的元素
      Returns:
      a new list with the element prepended | 前插元素后的新列表
    • append

      public PersistentList<E> append(E element)
      Description copied from interface: PersistentList
      Append an element to the end of this list (O(n)). 在列表末尾追加一个元素 (O(n))。
      Specified by:
      append in interface PersistentList<E>
      Parameters:
      element - the element to append | 要追加的元素
      Returns:
      a new list with the element appended | 追加元素后的新列表
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: PersistentList
      Check if this list is empty. 检查列表是否为空。
      Specified by:
      isEmpty in interface PersistentList<E>
      Returns:
      true if the list is empty | 如果列表为空则返回 true
    • contains

      public boolean contains(Object element)
      Description copied from interface: PersistentList
      Check if this list contains the given element. 检查列表是否包含给定元素。
      Specified by:
      contains in interface PersistentList<E>
      Parameters:
      element - the element to search for | 要搜索的元素
      Returns:
      true if the element is found | 如果找到元素则返回 true
    • reversed

      public PersistentList<E> reversed()
      Description copied from interface: PersistentList
      Return a reversed copy of this list (O(n)). 返回此列表的反转副本 (O(n))。
      Specified by:
      reversed in interface PersistentList<E>
      Returns:
      reversed list | 反转后的列表
    • map

      public <R> PersistentList<R> map(Function<? super E, ? extends R> fn)
      Description copied from interface: PersistentList
      Apply a function to each element and return a new list (O(n)). 对每个元素应用函数并返回新列表 (O(n))。
      Specified by:
      map in interface PersistentList<E>
      Type Parameters:
      R - result element type | 结果元素类型
      Parameters:
      fn - the mapping function | 映射函数
      Returns:
      a new list with mapped elements | 包含映射元素的新列表
    • filter

      public PersistentList<E> filter(Predicate<? super E> predicate)
      Description copied from interface: PersistentList
      Filter elements by a predicate and return a new list (O(n)). 按谓词过滤元素并返回新列表 (O(n))。
      Specified by:
      filter in interface PersistentList<E>
      Parameters:
      predicate - the filter predicate | 过滤谓词
      Returns:
      a new list with only matching elements | 仅包含匹配元素的新列表
    • toList

      public List<E> toList()
      Description copied from interface: PersistentList
      Convert this persistent list to a JDK List. 将此持久化列表转换为 JDK List
      Specified by:
      toList in interface PersistentList<E>
      Returns:
      an unmodifiable list containing all elements | 包含所有元素的不可修改列表
    • stream

      public Stream<E> stream()
      Description copied from interface: PersistentList
      Return a sequential stream over the elements. 返回元素上的顺序流。
      Specified by:
      stream in interface PersistentList<E>
      Returns:
      a stream | 流
    • iterator

      public Iterator<E> iterator()
      Description copied from interface: PersistentList
      Return an iterator over the elements. 返回元素上的迭代器。
      Specified by:
      iterator in interface PersistentList<E>
      Returns:
      an iterator | 迭代器
    • toString

      public 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.
    • head

      public E head()
      Returns the value of the head record component.
      Specified by:
      head in interface PersistentList<E>
      Returns:
      the value of the head record component
    • tail

      public PersistentList<E> tail()
      Returns the value of the tail record component.
      Specified by:
      tail in interface PersistentList<E>
      Returns:
      the value of the tail record component
    • size

      public int size()
      Returns the value of the size record component.
      Specified by:
      size in interface PersistentList<E>
      Returns:
      the value of the size record component