Class DoubleSet

java.lang.Object
cloud.opencode.base.collections.primitive.DoubleSet
All Implemented Interfaces:
Serializable

public final class DoubleSet extends Object implements Serializable
DoubleSet - Primitive double Set Implementation DoubleSet - 原始 double 集合实现

A set specialized for primitive double values to avoid boxing overhead.

专门用于原始 double 值的集合,以避免装箱开销。

Features | 主要功能:

  • No boxing overhead - 无装箱开销
  • Memory efficient - 内存高效
  • Fast operations - 快速操作
  • Correct NaN and -0.0 handling - 正确处理 NaN 和 -0.0

Usage Examples | 使用示例:

DoubleSet set = DoubleSet.create();
set.add(1.0);
set.add(2.5);
set.add(3.14);

boolean contains = set.contains(2.5);    // true
double[] array = set.toDoubleArray();     // [1.0, 2.5, 3.14]

// Iteration - 迭代
set.forEach(value -> System.out.println(value));

Performance | 性能特性:

  • add: O(1) average - add: O(1) 平均
  • remove: O(1) average - remove: O(1) 平均
  • contains: O(1) average - contains: O(1) 平均

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
Since:
JDK 25, opencode-base-collections V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • create

      public static DoubleSet create()
      Create an empty DoubleSet. 创建空 DoubleSet。
      Returns:
      new empty DoubleSet | 新空 DoubleSet
    • create

      public static DoubleSet create(int initialCapacity)
      Create a DoubleSet with initial capacity. 创建指定初始容量的 DoubleSet。
      Parameters:
      initialCapacity - initial capacity | 初始容量
      Returns:
      new empty DoubleSet | 新空 DoubleSet
    • of

      public static DoubleSet of(double... values)
      Create a DoubleSet from values. 从值创建 DoubleSet。
      Parameters:
      values - the values | 值
      Returns:
      new DoubleSet | 新 DoubleSet
    • from

      public static DoubleSet from(double[] array)
      Create a DoubleSet from a double array. 从 double 数组创建 DoubleSet。
      Parameters:
      array - the source array | 源数组
      Returns:
      new DoubleSet | 新 DoubleSet
    • from

      public static DoubleSet from(Collection<Double> collection)
      Create a DoubleSet from a Collection of Double. 从 Double 集合创建 DoubleSet。
      Parameters:
      collection - the source collection | 源集合
      Returns:
      new DoubleSet | 新 DoubleSet
      Throws:
      NullPointerException - if collection contains null elements | 如果集合包含 null 元素
    • add

      public boolean add(double value)
      Add a value to this set. 向此集合添加值。
      Parameters:
      value - the value | 值
      Returns:
      true if added | 如果添加则返回 true
    • addAll

      public void addAll(double... values)
      Add all values to this set. 向此集合添加所有值。
      Parameters:
      values - the values | 值
    • remove

      public boolean remove(double value)
      Remove a value from this set. 从此集合移除值。
      Parameters:
      value - the value | 值
      Returns:
      true if removed | 如果移除则返回 true
    • contains

      public boolean contains(double value)
      Check if this set contains the value. 检查此集合是否包含该值。
      Parameters:
      value - the value | 值
      Returns:
      true if contains | 如果包含则返回 true
    • size

      public int size()
      Return the size of this set. 返回此集合的大小。
      Returns:
      the size | 大小
    • isEmpty

      public boolean isEmpty()
      Check if this set is empty. 检查此集合是否为空。
      Returns:
      true if empty | 如果为空则返回 true
    • clear

      public void clear()
      Clear this set. 清空此集合。
    • toDoubleArray

      public double[] toDoubleArray()
      Return all values as a double array. 以 double 数组形式返回所有值。
      Returns:
      the values array | 值数组
    • toSet

      public Set<Double> toSet()
      Return all values as a boxed Set. 以装箱 Set 形式返回所有值。
      Returns:
      the boxed set | 装箱集合
    • forEach

      public void forEach(DoubleConsumer action)
      Apply action to each value. 对每个值应用操作。
      Parameters:
      action - the action | 操作
    • iterator

      public PrimitiveIterator.OfDouble iterator()
      Return an iterator over the values. 返回值的迭代器。
      Returns:
      the iterator | 迭代器
    • stream

      public DoubleStream stream()
      Return a DoubleStream of all values. 返回所有值的 DoubleStream。
      Returns:
      the stream | 流
    • addAll

      public void addAll(DoubleSet other)
      Add all values from another set. 从另一个集合添加所有值。
      Parameters:
      other - the other set | 另一个集合
    • removeAll

      public void removeAll(DoubleSet other)
      Remove all values in another set. 移除另一个集合中的所有值。
      Parameters:
      other - the other set | 另一个集合
    • retainAll

      public void retainAll(DoubleSet other)
      Retain only values in another set. 仅保留另一个集合中的值。
      Parameters:
      other - the other set | 另一个集合
    • 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