Class ForwardingList<E>
java.lang.Object
cloud.opencode.base.collections.ForwardingCollection<E>
cloud.opencode.base.collections.ForwardingList<E>
- Type Parameters:
E- element type | 元素类型
- All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, SequencedCollection<E>
ForwardingList - Abstract Decorator Base for List
ForwardingList - List 的抽象装饰器基类
An abstract base class that forwards all List method calls to a delegate.
Extends ForwardingCollection and adds List-specific method delegation.
Subclasses implement delegate() and can override individual methods
to add custom behavior.
将所有 List 方法调用转发给委托对象的抽象基类。扩展 ForwardingCollection
并添加 List 特定的方法委托。子类实现 delegate() 并可以重写单个方法以添加自定义行为。
Features | 主要功能:
- Decorator pattern for List - List 的装饰器模式
- All List methods forwarded - 所有 List 方法转发
- Includes index-based operations - 包含基于索引的操作
- ListIterator and subList delegation - ListIterator 和 subList 委托
Usage Examples | 使用示例:
// Create a read-only list wrapper
class UnmodifiableList<E> extends ForwardingList<E> {
private final List<E> delegate;
UnmodifiableList(List<E> delegate) {
this.delegate = delegate;
}
@Override protected List<E> delegate() { return delegate; }
@Override public boolean add(E e) {
throw new UnsupportedOperationException();
}
}
Security | 安全性:
- Thread-safe: Depends on delegate - 线程安全: 取决于委托对象
- Null-safe: Depends on delegate - 空值安全: 取决于委托对象
- Since:
- JDK 25, opencode-base-collections V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanaddAll(int index, Collection<? extends E> c) Add all elements at the given index by iterating throughadd(int, Object).delegate()Return the backing delegate list.get(int index) intintlistIterator(int index) remove(int index) subList(int fromIndex, int toIndex) Methods inherited from class ForwardingCollection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArray
-
Constructor Details
-
ForwardingList
protected ForwardingList()Protected constructor for subclasses. 子类的受保护构造方法。
-
-
Method Details
-
delegate
Return the backing delegate list. 返回后备委托列表。- Specified by:
delegatein classForwardingCollection<E>- Returns:
- the delegate list | 委托列表
-
add
-
addAll
Add all elements at the given index by iterating throughadd(int, Object). This ensures subclass overrides ofadd(int, E)are honored. 通过迭代调用add(int, Object)在指定位置添加所有元素。确保子类对add(int, E)的覆写被执行。 -
get
-
set
-
remove
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
subList
-