Class ForwardingMap<K,V>
java.lang.Object
cloud.opencode.base.collections.ForwardingMap<K,V>
- Type Parameters:
K- key type | 键类型V- value type | 值类型
- All Implemented Interfaces:
Map<K,V>
ForwardingMap - Abstract Decorator Base for Map
ForwardingMap - Map 的抽象装饰器基类
An abstract base class that forwards all Map method calls to a delegate.
Subclasses implement delegate() and can override individual methods
to add custom behavior such as logging, validation, or transformation.
将所有 Map 方法调用转发给委托对象的抽象基类。子类实现 delegate()
并可以重写单个方法以添加自定义行为,如日志记录、验证或转换。
Features | 主要功能:
- Decorator pattern for Map - Map 的装饰器模式
- All Map methods forwarded - 所有 Map 方法转发
- Override individual methods for custom behavior - 重写单个方法以自定义行为
- Consistent equals/hashCode/toString delegation - 一致的 equals/hashCode/toString 委托
Usage Examples | 使用示例:
// Create a case-insensitive map wrapper
class CaseInsensitiveMap<V> extends ForwardingMap<String, V> {
private final Map<String, V> delegate;
CaseInsensitiveMap(Map<String, V> delegate) {
this.delegate = delegate;
}
@Override protected Map<String, V> delegate() { return delegate; }
@Override public V put(String key, V value) {
return super.put(key.toLowerCase(), value);
}
}
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:
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) delegate()Return the backing delegate map.entrySet()booleaninthashCode()booleanisEmpty()keySet()voidPut all entries by iterating throughput(Object, Object).intsize()toString()values()Methods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
ForwardingMap
protected ForwardingMap()Protected constructor for subclasses. 子类的受保护构造方法。
-
-
Method Details
-
delegate
-
size
-
isEmpty
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
get
-
put
-
remove
-
putAll
Put all entries by iterating throughput(Object, Object). This ensures subclass overrides ofput()are honored. 通过迭代调用put(Object, Object)放入所有条目。确保子类对put()的覆写被执行。 -
clear
-
keySet
-
values
-
entrySet
-
toString
-
hashCode
-
equals
-