Class ImmutableClassToInstanceMap<B>
java.lang.Object
java.util.AbstractMap<Class<? extends B>, B>
cloud.opencode.base.collections.immutable.ImmutableClassToInstanceMap<B>
- Type Parameters:
B- base type | 基础类型
- All Implemented Interfaces:
Serializable, Map<Class<? extends B>, B>
public final class ImmutableClassToInstanceMap<B>
extends AbstractMap<Class<? extends B>, B>
implements Serializable
ImmutableClassToInstanceMap - Immutable Class to Instance Map
ImmutableClassToInstanceMap - 不可变类型实例映射
A type-safe map from Class objects to instances of that class. Cannot be modified after creation.
从 Class 对象到该类实例的类型安全映射。创建后不能修改。
Features | 主要功能:
- Immutable - 不可变
- Thread-safe - 线程安全
- Type-safe instance retrieval - 类型安全的实例获取
Usage Examples | 使用示例:
ImmutableClassToInstanceMap<Object> map = ImmutableClassToInstanceMap.builder()
.put(String.class, "hello")
.put(Integer.class, 42)
.build();
String str = map.getInstance(String.class); // Type-safe
Integer num = map.getInstance(Integer.class);
Performance | 性能特性:
- getInstance: O(1) - getInstance: O(1)
- containsKey: O(1) - containsKey: O(1)
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Yes (nulls not allowed) - 空值安全: 是(不允许空值)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for ImmutableClassToInstanceMap.Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Method Summary
Modifier and TypeMethodDescriptionstatic <B> ImmutableClassToInstanceMap.Builder<B> builder()Create a builder.voidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) static <B> ImmutableClassToInstanceMap<B> Copy from a map.entrySet()<T extends B>
TgetInstance(Class<T> type) Get the instance for the given type in a type-safe manner.booleanisEmpty()static <B> ImmutableClassToInstanceMap<B> of()Return an empty immutable class to instance map.static <B, T extends B>
ImmutableClassToInstanceMap<B> Return an immutable class to instance map with one entry.intsize()Methods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Method Details
-
of
Return an empty immutable class to instance map. 返回空不可变类型实例映射。- Type Parameters:
B- base type | 基础类型- Returns:
- empty immutable class to instance map | 空不可变类型实例映射
-
of
Return an immutable class to instance map with one entry. 返回包含一个条目的不可变类型实例映射。- Type Parameters:
B- base type | 基础类型T- instance type | 实例类型- Parameters:
type- the class | 类value- the instance | 实例- Returns:
- immutable class to instance map | 不可变类型实例映射
-
copyOf
public static <B> ImmutableClassToInstanceMap<B> copyOf(Map<? extends Class<? extends B>, ? extends B> map) Copy from a map. 从映射复制。- Type Parameters:
B- base type | 基础类型- Parameters:
map- the map | 映射- Returns:
- immutable class to instance map | 不可变类型实例映射
-
builder
Create a builder. 创建构建器。- Type Parameters:
B- base type | 基础类型- Returns:
- builder | 构建器
-
getInstance
-
size
-
isEmpty
-
containsKey
- Specified by:
containsKeyin interfaceMap<Class<? extends B>, B>- Overrides:
containsKeyin classAbstractMap<Class<? extends B>, B>
-
containsValue
- Specified by:
containsValuein interfaceMap<Class<? extends B>, B>- Overrides:
containsValuein classAbstractMap<Class<? extends B>, B>
-
get
-
entrySet
-
put
-
remove
-
clear
-