Class ForwardingSet<E>
java.lang.Object
cloud.opencode.base.collections.ForwardingCollection<E>
cloud.opencode.base.collections.ForwardingSet<E>
- Type Parameters:
E- element type | 元素类型
- All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
ForwardingSet - Abstract Decorator Base for Set
ForwardingSet - Set 的抽象装饰器基类
An abstract base class that forwards all Set method calls to a delegate.
Extends ForwardingCollection with Set-specific equals and hashCode semantics.
Subclasses implement delegate() and can override individual methods
to add custom behavior.
将所有 Set 方法调用转发给委托对象的抽象基类。扩展 ForwardingCollection
并使用 Set 特定的 equals 和 hashCode 语义。子类实现 delegate()
并可以重写单个方法以添加自定义行为。
Features | 主要功能:
- Decorator pattern for Set - Set 的装饰器模式
- All Set methods forwarded - 所有 Set 方法转发
- Set-specific equals/hashCode semantics - Set 特定的 equals/hashCode 语义
- Override methods for custom behavior - 重写方法以自定义行为
Usage Examples | 使用示例:
// Create a validated set wrapper
class NonNullSet<E> extends ForwardingSet<E> {
private final Set<E> delegate;
NonNullSet(Set<E> delegate) {
this.delegate = delegate;
}
@Override protected Set<E> delegate() { return delegate; }
@Override public boolean add(E e) {
Objects.requireNonNull(e, "null elements not allowed");
return super.add(e);
}
}
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
Methods inherited from class ForwardingCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArray
-
Constructor Details
-
ForwardingSet
protected ForwardingSet()Protected constructor for subclasses. 子类的受保护构造方法。
-
-
Method Details
-
delegate
Return the backing delegate set. 返回后备委托集合。- Specified by:
delegatein classForwardingCollection<E>- Returns:
- the delegate set | 委托集合
-
equals
- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceSet<E>- Overrides:
equalsin classForwardingCollection<E>
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceSet<E>- Overrides:
hashCodein classForwardingCollection<E>
-