Class IntIntMap
java.lang.Object
cloud.opencode.base.collections.primitive.IntIntMap
- All Implemented Interfaces:
Serializable
IntIntMap - Primitive int-to-int Map Implementation
IntIntMap - 原始 int 到 int 映射实现
A map specialized for primitive int keys and values to avoid boxing overhead.
专门用于原始 int 键和值的映射,以避免装箱开销。
Features | 主要功能:
- No boxing overhead - 无装箱开销
- Memory efficient - 内存高效
- Fast operations - 快速操作
Usage Examples | 使用示例:
IntIntMap map = IntIntMap.create();
map.put(1, 100);
map.put(2, 200);
int value = map.get(1); // 100
int def = map.getOrDefault(3, -1); // -1
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: No (primitive values, no null) - 否(原始值,无null)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for int-int consumer. int-int 消费者函数式接口。 -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear this map.booleancontainsKey(int key) Check if this map contains the key.booleancontainsValue(int value) Check if this map contains the value.static IntIntMapcreate()Create an empty IntIntMap.static IntIntMapcreate(int initialCapacity) Create an IntIntMap with initial capacity.booleanvoidforEach(IntIntMap.IntIntConsumer action) Apply action to each entry.intget(int key) Get the value for a key.intgetOrDefault(int 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 IntSet.intput(int key, int value) Put a key-value pair.intremove(int key) Remove a key-value pair.intsize()Return the size of this map.toString()int[]Return all values as an array.
-
Method Details
-
create
Create an empty IntIntMap. 创建空 IntIntMap。- Returns:
- new empty IntIntMap | 新空 IntIntMap
-
create
Create an IntIntMap with initial capacity. 创建指定初始容量的 IntIntMap。- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new empty IntIntMap | 新空 IntIntMap
-
put
public int put(int key, int value) Put a key-value pair. 放入键值对。- Parameters:
key- the key | 键value- the value | 值- Returns:
- the old value or NO_VALUE | 旧值或 NO_VALUE
-
get
public int get(int key) Get the value for a key. 获取键对应的值。- Parameters:
key- the key | 键- Returns:
- the value | 值
- Throws:
NoSuchElementException- if key not found | 如果键未找到
-
getOrDefault
public int getOrDefault(int key, int defaultValue) Get the value for a key or default. 获取键对应的值或默认值。- Parameters:
key- the key | 键defaultValue- the default value | 默认值- Returns:
- the value or default | 值或默认值
-
remove
public int remove(int key) Remove a key-value pair. 移除键值对。- Parameters:
key- the key | 键- Returns:
- the old value or NO_VALUE | 旧值或 NO_VALUE
-
containsKey
public boolean containsKey(int key) Check if this map contains the key. 检查此映射是否包含该键。- Parameters:
key- the key | 键- Returns:
- true if contains | 如果包含则返回 true
-
containsValue
public boolean containsValue(int value) Check if this map contains the value. 检查此映射是否包含该值。- Parameters:
value- the value | 值- 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. 清空此映射。 -
keySet
-
valuesToArray
public int[] valuesToArray()Return all values as an array. 以数组形式返回所有值。- Returns:
- the values | 值
-
forEach
Apply action to each entry. 对每个条目应用操作。- Parameters:
action- the action | 操作
-
equals
-
hashCode
-
toString
-