Class IntObjectMap<V>

java.lang.Object
cloud.opencode.base.collections.primitive.IntObjectMap<V>
Type Parameters:
V - value type | 值类型
All Implemented Interfaces:
Serializable

public final class IntObjectMap<V> extends Object implements Serializable
IntObjectMap - Primitive int Key to Object Value Map IntObjectMap - 原始 int 键到对象值映射

A map with primitive int keys and object values to avoid key boxing overhead.

具有原始 int 键和对象值的映射,以避免键装箱开销。

Features | 主要功能:

  • No key boxing overhead - 无键装箱开销
  • Memory efficient - 内存高效
  • Fast int key operations - 快速 int 键操作

Usage Examples | 使用示例:

IntObjectMap<String> map = IntObjectMap.create();
map.put(1, "one");
map.put(2, "two");

String value = map.get(1);  // "one"

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: Partial (values can be null) - 部分(值可以为null)
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • create

      public static <V> IntObjectMap<V> create()
      Create an empty IntObjectMap. 创建空 IntObjectMap。
      Type Parameters:
      V - value type | 值类型
      Returns:
      new empty IntObjectMap | 新空 IntObjectMap
    • create

      public static <V> IntObjectMap<V> create(int initialCapacity)
      Create an IntObjectMap with initial capacity. 创建指定初始容量的 IntObjectMap。
      Type Parameters:
      V - value type | 值类型
      Parameters:
      initialCapacity - initial capacity | 初始容量
      Returns:
      new empty IntObjectMap | 新空 IntObjectMap
    • put

      public V put(int key, V value)
      Put a key-value pair. 放入键值对。
      Parameters:
      key - the key | 键
      value - the value | 值
      Returns:
      the old value or null | 旧值或 null
    • get

      public V get(int key)
      Get the value for a key. 获取键对应的值。
      Parameters:
      key - the key | 键
      Returns:
      the value or null | 值或 null
    • getOrDefault

      public V getOrDefault(int key, V defaultValue)
      Get the value for a key or default. 获取键对应的值或默认值。
      Parameters:
      key - the key | 键
      defaultValue - the default value | 默认值
      Returns:
      the value or default | 值或默认值
    • remove

      public V remove(int key)
      Remove a key-value pair. 移除键值对。
      Parameters:
      key - the key | 键
      Returns:
      the old value or null | 旧值或 null
    • 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(Object 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

      public IntSet keySet()
      Return all keys as an IntSet. 以 IntSet 形式返回所有键。
      Returns:
      the keys | 键
    • values

      public Collection<V> values()
      Return all values as a collection. 以集合形式返回所有值。
      Returns:
      the values | 值
    • forEach

      public void forEach(IntObjectMap.IntObjectConsumer<? super V> action)
      Apply action to each entry. 对每个条目应用操作。
      Parameters:
      action - the action | 操作
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object