Class LongLongMap
java.lang.Object
cloud.opencode.base.collections.primitive.LongLongMap
- All Implemented Interfaces:
Serializable
LongLongMap - Primitive long-to-long Map Implementation
LongLongMap - 原始 long 到 long 映射实现
A map specialized for primitive long keys and values to avoid boxing overhead.
专门用于原始 long 键和值的映射,以避免装箱开销。
Note: Long.MIN_VALUE cannot be used as a value because it serves
as the internal sentinel for "no value". Attempting to store Long.MIN_VALUE will throw
IllegalArgumentException.
注意: Long.MIN_VALUE 不能用作值,因为它用作内部"无值"哨兵。
尝试存储 Long.MIN_VALUE 将抛出 IllegalArgumentException。
Features | 主要功能:
- No boxing overhead - 无装箱开销
- Memory efficient - 内存高效
- Fast operations - 快速操作
Usage Examples | 使用示例:
LongLongMap map = LongLongMap.create();
map.put(1L, 100L);
map.put(2L, 200L);
long value = map.get(1L); // 100L
long def = map.getOrDefault(3L, -1L); // -1L
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.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for long-long consumer. long-long 消费者函数式接口。 -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear this map.booleancontainsKey(long key) Check if this map contains the key.booleancontainsValue(long value) Check if this map contains the value.static LongLongMapcreate()Create an empty LongLongMap.static LongLongMapcreate(int initialCapacity) Create a LongLongMap with initial capacity.booleanvoidforEach(LongLongMap.LongLongConsumer action) Apply action to each entry.longget(long key) Get the value for a key.longgetOrDefault(long key, long defaultValue) Get the value for a key or default.inthashCode()booleanisEmpty()Check if this map is empty.long[]keys()Return all keys as a long array.static LongLongMapof(long... kvPairs) Create a LongLongMap from key-value pairs.longput(long key, long value) Put a key-value pair.longremove(long key) Remove a key-value pair.intsize()Return the size of this map.toString()long[]values()Return all values as a long array.
-
Method Details
-
create
Create an empty LongLongMap. 创建空 LongLongMap。- Returns:
- new empty LongLongMap | 新空 LongLongMap
-
create
Create a LongLongMap with initial capacity. 创建指定初始容量的 LongLongMap。- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new empty LongLongMap | 新空 LongLongMap
-
of
Create a LongLongMap from key-value pairs. 从键值对创建 LongLongMap。Arguments must be provided in pairs: key1, value1, key2, value2, ...
参数必须成对提供:key1, value1, key2, value2, ...
- Parameters:
kvPairs- key-value pairs | 键值对- Returns:
- new LongLongMap | 新 LongLongMap
- Throws:
IllegalArgumentException- if odd number of arguments | 如果参数数量为奇数
-
put
public long put(long key, long value) Put a key-value pair. 放入键值对。- Parameters:
key- the key | 键value- the value | 值- Returns:
- the old value or NO_VALUE | 旧值或 NO_VALUE
-
get
public long get(long key) Get the value for a key. 获取键对应的值。- Parameters:
key- the key | 键- Returns:
- the value | 值
- Throws:
NoSuchElementException- if key not found | 如果键未找到
-
getOrDefault
public long getOrDefault(long key, long defaultValue) Get the value for a key or default. 获取键对应的值或默认值。- Parameters:
key- the key | 键defaultValue- the default value | 默认值- Returns:
- the value or default | 值或默认值
-
remove
public long remove(long key) Remove a key-value pair. 移除键值对。- Parameters:
key- the key | 键- Returns:
- the old value or NO_VALUE | 旧值或 NO_VALUE
-
containsKey
public boolean containsKey(long key) Check if this map contains the key. 检查此映射是否包含该键。- Parameters:
key- the key | 键- Returns:
- true if contains | 如果包含则返回 true
-
containsValue
public boolean containsValue(long 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. 清空此映射。 -
keys
public long[] keys()Return all keys as a long array. 以 long 数组形式返回所有键。- Returns:
- the keys | 键数组
-
values
public long[] values()Return all values as a long array. 以 long 数组形式返回所有值。- Returns:
- the values | 值数组
-
forEach
Apply action to each entry. 对每个条目应用操作。- Parameters:
action- the action | 操作
-
equals
-
hashCode
-
toString
-