Class ObjectIntMap<K>
java.lang.Object
cloud.opencode.base.collections.primitive.ObjectIntMap<K>
- Type Parameters:
K- key type | 键类型
- All Implemented Interfaces:
Serializable
ObjectIntMap - Object Key to Primitive int Value Map
ObjectIntMap - 对象键到原始 int 值映射
A map with object keys and primitive int values to avoid value boxing overhead.
具有对象键和原始 int 值的映射,以避免值装箱开销。
Features | 主要功能:
- No value boxing overhead - 无值装箱开销
- Memory efficient - 内存高效
- Fast object key operations - 快速对象键操作
- addTo for atomic increment - addTo 原子增量操作
Usage Examples | 使用示例:
ObjectIntMap<String> map = ObjectIntMap.create();
map.put("apple", 3);
map.put("banana", 5);
int value = map.get("apple"); // 3
map.addTo("apple", 2); // now 5
Performance | 性能特性:
- put: O(1) average - put: O(1) 平均
- get: O(1) average - get: O(1) 平均
- remove: O(1) average - remove: O(1) 平均
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: Keys cannot be null - 键不能为null
- Since:
- JDK 25, opencode-base-collections V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdd increment to the value associated with key.voidclear()Clear this map.booleancontainsKey(K key) Check if this map contains the key.static <K> ObjectIntMap<K> create()Create an empty ObjectIntMap.static <K> ObjectIntMap<K> create(int initialCapacity) Create an ObjectIntMap with initial capacity.booleanvoidforEach(ObjIntConsumer<? super K> action) Apply action to each entry.intGet the value for a key.intgetOrDefault(K key, int defaultValue) Get the value for a key or default.inthashCode()booleanisEmpty()Check if this map is empty.keySet()Return all keys as an unmodifiable set.voidPut a key-value pair.intRemove a key-value pair.intsize()Return the size of this map.toString()int[]Return all values as an int array.
-
Method Details
-
create
Create an empty ObjectIntMap. 创建空 ObjectIntMap。- Type Parameters:
K- key type | 键类型- Returns:
- new empty ObjectIntMap | 新空 ObjectIntMap
-
create
Create an ObjectIntMap with initial capacity. 创建指定初始容量的 ObjectIntMap。- Type Parameters:
K- key type | 键类型- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new empty ObjectIntMap | 新空 ObjectIntMap
-
put
Put a key-value pair. 放入键值对。- Parameters:
key- the key (must not be null) | 键(不能为null)value- the value | 值
-
get
Get the value for a key. 获取键对应的值。- Parameters:
key- the key | 键- Returns:
- the value | 值
- Throws:
NoSuchElementException- if key not found | 如果键未找到
-
getOrDefault
Get the value for a key or default. 获取键对应的值或默认值。- Parameters:
key- the key | 键defaultValue- the default value | 默认值- Returns:
- the value or default | 值或默认值
-
remove
Remove a key-value pair. 移除键值对。- Parameters:
key- the key | 键- Returns:
- the old value | 旧值
- Throws:
NoSuchElementException- if key not found | 如果键未找到
-
containsKey
Check if this map contains the key. 检查此映射是否包含该键。- Parameters:
key- the key | 键- Returns:
- true if contains | 如果包含则返回 true
-
size
public int size()Return the size of this map. 返回此映射的大小。- Returns:
- the size | 大小
-
isEmpty
public boolean isEmpty()Check if this map is empty. 检查此映射是否为空。- Returns:
- true if empty | 如果为空则返回 true
-
clear
public void clear()Clear this map. 清空此映射。 -
addTo
Add increment to the value associated with key. If the key does not exist, set it to increment. 将增量添加到与键关联的值。如果键不存在,则设置为增量。- Parameters:
key- the key | 键increment- the increment | 增量
-
forEach
Apply action to each entry. 对每个条目应用操作。- Parameters:
action- the action | 操作
-
keySet
-
toValueArray
public int[] toValueArray()Return all values as an int array. 以 int 数组形式返回所有值。- Returns:
- the values | 值数组
-
equals
-
hashCode
-
toString
-