Class ObjectDoubleMap<K>

java.lang.Object
cloud.opencode.base.collections.primitive.ObjectDoubleMap<K>
Type Parameters:
K - key type | 键类型
All Implemented Interfaces:
Serializable

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

A map with object keys and primitive double values to avoid value boxing overhead.

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

Features | 主要功能:

  • No value boxing overhead - 无值装箱开销
  • Memory efficient - 内存高效
  • Fast object key operations - 快速对象键操作
  • addTo for atomic increment - addTo 原子增量操作

Usage Examples | 使用示例:

ObjectDoubleMap<String> map = ObjectDoubleMap.create();
map.put("apple", 3.14);
map.put("banana", 2.71);

double value = map.get("apple");  // 3.14
map.addTo("apple", 1.0);         // now 4.14

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 Details

    • create

      public static <K> ObjectDoubleMap<K> create()
      Create an empty ObjectDoubleMap. 创建空 ObjectDoubleMap。
      Type Parameters:
      K - key type | 键类型
      Returns:
      new empty ObjectDoubleMap | 新空 ObjectDoubleMap
    • create

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

      public void put(K key, double value)
      Put a key-value pair. 放入键值对。
      Parameters:
      key - the key (must not be null) | 键(不能为null)
      value - the value | 值
    • get

      public double get(K key)
      Get the value for a key. 获取键对应的值。
      Parameters:
      key - the key | 键
      Returns:
      the value | 值
      Throws:
      NoSuchElementException - if key not found | 如果键未找到
    • getOrDefault

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

      public double remove(K key)
      Remove a key-value pair. 移除键值对。
      Parameters:
      key - the key | 键
      Returns:
      the old value | 旧值
      Throws:
      NoSuchElementException - if key not found | 如果键未找到
    • containsKey

      public boolean containsKey(K key)
      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

      public void addTo(K key, double increment)
      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

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

      public Set<K> keySet()
      Return all keys as an unmodifiable set. 以不可修改集合形式返回所有键。
      Returns:
      the keys | 键集合
    • toValueArray

      public double[] toValueArray()
      Return all values as a double array. 以 double 数组形式返回所有值。
      Returns:
      the values | 值数组
    • 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