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
-
Nested Class Summary
Nested classes/interfaces inherited from interface PersistentList
PersistentList.Cons<E>, PersistentList.Nil<E> -
Constructor Summary
ConstructorsConstructorDescriptionCons(E head, PersistentList<E> tail, int size) Canonical constructor with validation. -
Method Summary
Modifier and TypeMethodDescriptionAppend an element to the end of this list (O(n)).booleanCheck if this list contains the given element.final booleanIndicates whether some other object is "equal to" this one.Filter elements by a predicate and return a new list (O(n)).final inthashCode()Returns a hash code value for this object.head()Returns the value of theheadrecord component.booleanisEmpty()Check if this list is empty.iterator()Return an iterator over the elements.<R> PersistentList<R> Apply a function to each element and return a new list (O(n)).Prepend an element to the front of this list (O(1)).reversed()Return a reversed copy of this list (O(n)).intsize()Returns the value of thesizerecord component.stream()Return a sequential stream over the elements.tail()Returns the value of thetailrecord component.toList()Convert this persistent list to a JDKList.toString()Returns a string representation of this record class.
-
Constructor Details
-
Cons
Canonical constructor with validation. 带验证的规范构造方法。
-
-
Method Details
-
prepend
Description copied from interface:PersistentListPrepend an element to the front of this list (O(1)). 在列表前端插入一个元素 (O(1))。- Specified by:
prependin interfacePersistentList<E>- Parameters:
element- the element to prepend | 要前插的元素- Returns:
- a new list with the element prepended | 前插元素后的新列表
-
append
Description copied from interface:PersistentListAppend an element to the end of this list (O(n)). 在列表末尾追加一个元素 (O(n))。- Specified by:
appendin interfacePersistentList<E>- Parameters:
element- the element to append | 要追加的元素- Returns:
- a new list with the element appended | 追加元素后的新列表
-
isEmpty
public boolean isEmpty()Description copied from interface:PersistentListCheck if this list is empty. 检查列表是否为空。- Specified by:
isEmptyin interfacePersistentList<E>- Returns:
- true if the list is empty | 如果列表为空则返回 true
-
contains
Description copied from interface:PersistentListCheck if this list contains the given element. 检查列表是否包含给定元素。- Specified by:
containsin interfacePersistentList<E>- Parameters:
element- the element to search for | 要搜索的元素- Returns:
- true if the element is found | 如果找到元素则返回 true
-
reversed
Description copied from interface:PersistentListReturn a reversed copy of this list (O(n)). 返回此列表的反转副本 (O(n))。- Specified by:
reversedin interfacePersistentList<E>- Returns:
- reversed list | 反转后的列表
-
map
Description copied from interface:PersistentListApply a function to each element and return a new list (O(n)). 对每个元素应用函数并返回新列表 (O(n))。- Specified by:
mapin interfacePersistentList<E>- Type Parameters:
R- result element type | 结果元素类型- Parameters:
fn- the mapping function | 映射函数- Returns:
- a new list with mapped elements | 包含映射元素的新列表
-
filter
Description copied from interface:PersistentListFilter elements by a predicate and return a new list (O(n)). 按谓词过滤元素并返回新列表 (O(n))。- Specified by:
filterin interfacePersistentList<E>- Parameters:
predicate- the filter predicate | 过滤谓词- Returns:
- a new list with only matching elements | 仅包含匹配元素的新列表
-
toList
Description copied from interface:PersistentList- Specified by:
toListin interfacePersistentList<E>- Returns:
- an unmodifiable list containing all elements | 包含所有元素的不可修改列表
-
stream
Description copied from interface:PersistentListReturn a sequential stream over the elements. 返回元素上的顺序流。- Specified by:
streamin interfacePersistentList<E>- Returns:
- a stream | 流
-
iterator
Description copied from interface:PersistentListReturn an iterator over the elements. 返回元素上的迭代器。- Specified by:
iteratorin interfacePersistentList<E>- Returns:
- an iterator | 迭代器
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
head
-
tail
Returns the value of thetailrecord component.- Specified by:
tailin interfacePersistentList<E>- Returns:
- the value of the
tailrecord component
-
size
public int size()Returns the value of thesizerecord component.- Specified by:
sizein interfacePersistentList<E>- Returns:
- the value of the
sizerecord component
-