Class IntSet
java.lang.Object
cloud.opencode.base.collections.primitive.IntSet
- All Implemented Interfaces:
Serializable
IntSet - Primitive int Set Implementation
IntSet - 原始 int 集合实现
A set specialized for primitive int values to avoid boxing overhead.
专门用于原始 int 值的集合,以避免装箱开销。
Features | 主要功能:
- No boxing overhead - 无装箱开销
- Memory efficient - 内存高效
- Fast operations - 快速操作
Usage Examples | 使用示例:
IntSet set = IntSet.create();
set.add(1);
set.add(2);
set.add(3);
boolean contains = set.contains(2); // true
int[] array = set.toIntArray(); // [1, 2, 3]
// 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.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for int consumer. int 消费者函数式接口。 -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int value) Add a value to this set.voidAdd all values from another set.voidclear()Clear this set.booleancontains(int value) Check if this set contains the value.static IntSetcreate()Create an empty IntSet.static IntSetcreate(int initialCapacity) Create an IntSet with initial capacity.booleanvoidforEach(IntSet.IntConsumer action) Apply action to each value.inthashCode()booleanisEmpty()Check if this set is empty.iterator()Return an iterator over the values.static IntSetof(int... values) Create an IntSet from values.booleanremove(int value) Remove a value from this set.voidRemove all values in another set.voidRetain only values in another set.intsize()Return the size of this set.int[]Return all values as an array.toString()
-
Method Details
-
create
Create an empty IntSet. 创建空 IntSet。- Returns:
- new empty IntSet | 新空 IntSet
-
create
Create an IntSet with initial capacity. 创建指定初始容量的 IntSet。- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new empty IntSet | 新空 IntSet
-
of
Create an IntSet from values. 从值创建 IntSet。- Parameters:
values- the values | 值- Returns:
- new IntSet | 新 IntSet
-
add
public boolean add(int value) Add a value to this set. 向此集合添加值。- Parameters:
value- the value | 值- Returns:
- true if added | 如果添加则返回 true
-
remove
public boolean remove(int value) Remove a value from this set. 从此集合移除值。- Parameters:
value- the value | 值- Returns:
- true if removed | 如果移除则返回 true
-
contains
public boolean contains(int 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. 清空此集合。 -
toIntArray
public int[] toIntArray()Return all values as an array. 以数组形式返回所有值。- Returns:
- the values array | 值数组
-
forEach
Apply action to each value. 对每个值应用操作。- Parameters:
action- the action | 操作
-
iterator
Return an iterator over the values. 返回值的迭代器。- Returns:
- the iterator | 迭代器
-
addAll
Add all values from another set. 从另一个集合添加所有值。- Parameters:
other- the other set | 另一个集合
-
removeAll
Remove all values in another set. 移除另一个集合中的所有值。- Parameters:
other- the other set | 另一个集合
-
retainAll
Retain only values in another set. 仅保留另一个集合中的值。- Parameters:
other- the other set | 另一个集合
-
equals
-
hashCode
-
toString
-