Class OpenSet
java.lang.Object
cloud.opencode.base.collections.OpenSet
OpenSet - Set Facade Utility Class
OpenSet - Set 门面工具类
Provides comprehensive set operations including creation, set algebra, filtering, and querying.
提供全面的 Set 操作,包括创建、集合代数、过滤和查询。
Features | 主要功能:
- Factory methods for set creation - Set 创建工厂方法
- Set algebra operations - 集合代数运算
- Set filtering - Set 过滤
- Power set and combinations - 幂集和组合
Usage Examples | 使用示例:
// Create set - 创建 Set
Set<String> set = OpenSet.of("a", "b", "c");
// Union - 并集
SetView<String> union = OpenSet.union(set1, set2);
// Intersection - 交集
SetView<String> intersection = OpenSet.intersection(set1, set2);
// Power set - 幂集
Set<Set<String>> powerSet = OpenSet.powerSet(set);
Performance | 性能特性:
- Most operations: O(n) - 大多数操作: O(n)
- Contains: O(1) for HashSet - 包含: HashSet 为 O(1)
- Power set: O(2^n) - 幂集: O(2^n)
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> SetAlgebra<E> Get the SetAlgebra interface for the set.cartesianProduct(Set<? extends E>... sets) Compute Cartesian product of sets.combinations(Set<E> set, int size) Compute combinations of given size.static <E> SetView<E> difference(Set<E> set1, Set<?> set2) Compute difference of two sets as a SetView.static booleanCheck if sets are disjoint.static booleanCheck if sets are equal (same elements).static <E> Set<E> Filter set by predicate.static <E> HashSet<E> Create a HashSet from an Iterable.static <E> SetView<E> intersection(Set<E> set1, Set<?> set2) Compute intersection of two sets as a SetView.static booleanCheck if one set is a subset of another.static <E> Set<E> Create a concurrent hash set.static <E> HashSet<E> Create an empty HashSet.static <E> LinkedHashSet<E> Create an empty LinkedHashSet.static <E extends Comparable<E>>
TreeSet<E> Create an empty TreeSet.static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator) Create a TreeSet with comparator.static <E> HashSet<E> of(E... elements) Create a HashSet with elements.Compute power set (all subsets) of a set.static <E> SetView<E> symmetricDifference(Set<? extends E> set1, Set<? extends E> set2) Compute symmetric difference of two sets as a SetView.static <E> SetView<E> Compute union of two sets as a SetView.static <E> HashSet<E> withExpectedSize(int expectedSize) Create a HashSet with expected size.
-
Method Details
-
newHashSet
Create an empty HashSet. 创建空的 HashSet。- Type Parameters:
E- element type | 元素类型- Returns:
- new HashSet | 新的 HashSet
-
of
Create a HashSet with elements. 创建包含元素的 HashSet。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- the elements | 元素- Returns:
- new HashSet | 新的 HashSet
-
from
-
withExpectedSize
Create a HashSet with expected size. 创建具有预期大小的 HashSet。- Type Parameters:
E- element type | 元素类型- Parameters:
expectedSize- expected size | 预期大小- Returns:
- new HashSet | 新的 HashSet
-
newLinkedHashSet
Create an empty LinkedHashSet. 创建空的 LinkedHashSet。- Type Parameters:
E- element type | 元素类型- Returns:
- new LinkedHashSet | 新的 LinkedHashSet
-
newTreeSet
Create an empty TreeSet. 创建空的 TreeSet。- Type Parameters:
E- element type | 元素类型- Returns:
- new TreeSet | 新的 TreeSet
-
newTreeSet
Create a TreeSet with comparator. 创建具有比较器的 TreeSet。- Type Parameters:
E- element type | 元素类型- Parameters:
comparator- the comparator | 比较器- Returns:
- new TreeSet | 新的 TreeSet
-
newConcurrentHashSet
Create a concurrent hash set. 创建并发哈希集合。- Type Parameters:
E- element type | 元素类型- Returns:
- new concurrent set | 新的并发 Set
-
union
-
intersection
-
difference
-
symmetricDifference
Compute symmetric difference of two sets as a SetView. 计算两个集合的对称差集视图。- Type Parameters:
E- element type | 元素类型- Parameters:
set1- first set | 第一个集合set2- second set | 第二个集合- Returns:
- symmetric difference view | 对称差集视图
-
powerSet
-
combinations
-
cartesianProduct
Compute Cartesian product of sets. 计算集合的笛卡尔积。- Type Parameters:
E- element type | 元素类型- Parameters:
sets- the sets | 集合- Returns:
- Cartesian product | 笛卡尔积
-
filter
-
algebra
Get the SetAlgebra interface for the set. 获取集合的 SetAlgebra 接口。- Type Parameters:
E- element type | 元素类型- Parameters:
set- the set | 集合- Returns:
- SetAlgebra instance | SetAlgebra 实例
-
disjoint
-
isSubset
-
equals
-