Class MutableClassToInstanceMap<B>
java.lang.Object
java.util.AbstractMap<Class<? extends B>, B>
cloud.opencode.base.collections.specialized.MutableClassToInstanceMap<B>
- Type Parameters:
B- base type | 基础类型
- All Implemented Interfaces:
ClassToInstanceMap<B>, Serializable, Map<Class<? extends B>, B>
public final class MutableClassToInstanceMap<B>
extends AbstractMap<Class<? extends B>, B>
implements ClassToInstanceMap<B>, Serializable
MutableClassToInstanceMap - Mutable Class to Instance Map Implementation
MutableClassToInstanceMap - 可变类实例映射实现
A mutable type-safe map from Class objects to instances of that class.
从 Class 对象到该类实例的可变类型安全映射。
Features | 主要功能:
- Type-safe instance retrieval - 类型安全的实例获取
- Type-safe instance storage - 类型安全的实例存储
- Mutable - 可变
Usage Examples | 使用示例:
MutableClassToInstanceMap<Object> map = MutableClassToInstanceMap.create();
map.putInstance(String.class, "hello");
map.putInstance(Integer.class, 42);
String str = map.getInstance(String.class); // "hello"
Integer num = map.getInstance(Integer.class); // 42
// Also supports Map interface
map.put(Double.class, 3.14);
Performance | 性能特性:
- getInstance: O(1) - getInstance: O(1)
- putInstance: O(1) - putInstance: O(1)
- containsKey: O(1) - containsKey: O(1)
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: No (nulls not allowed) - 空值安全: 否(不允许空值)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) static <B> MutableClassToInstanceMap<B> create()Create a new MutableClassToInstanceMap backed by a HashMap.static <B> MutableClassToInstanceMap<B> Create a new MutableClassToInstanceMap backed by the given map.entrySet()boolean<T extends B>
TgetInstance(Class<T> type) Get the instance for the given type in a type-safe manner.inthashCode()booleanisEmpty()keySet()void<T extends B>
TputInstance(Class<T> type, T value) Put the instance for the given type in a type-safe manner.intsize()toString()values()Methods inherited from class AbstractMap
cloneMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Method Details
-
create
Create a new MutableClassToInstanceMap backed by a HashMap. 创建由 HashMap 支持的新 MutableClassToInstanceMap。- Type Parameters:
B- base type | 基础类型- Returns:
- new MutableClassToInstanceMap | 新 MutableClassToInstanceMap
-
create
Create a new MutableClassToInstanceMap backed by the given map. 创建由给定映射支持的新 MutableClassToInstanceMap。- Type Parameters:
B- base type | 基础类型- Parameters:
backingMap- the backing map | 支持映射- Returns:
- new MutableClassToInstanceMap | 新 MutableClassToInstanceMap
-
getInstance
Description copied from interface:ClassToInstanceMapGet the instance for the given type in a type-safe manner. 以类型安全的方式获取给定类型的实例。- Specified by:
getInstancein interfaceClassToInstanceMap<B>- Type Parameters:
T- the type | 类型- Parameters:
type- the class | 类- Returns:
- the instance, or null if not found | 实例,未找到则返回 null
-
putInstance
Description copied from interface:ClassToInstanceMapPut the instance for the given type in a type-safe manner. 以类型安全的方式放入给定类型的实例。- Specified by:
putInstancein interfaceClassToInstanceMap<B>- Type Parameters:
T- the type | 类型- Parameters:
type- the class | 类value- the instance | 实例- Returns:
- the previous instance, or null if none | 之前的实例,如果没有则返回 null
-
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
-
put
-
remove
-
putAll
-
clear
-
keySet
-
values
-
entrySet
-
equals
-
hashCode
-
toString
-