Interface SetAlgebra<E>
- Type Parameters:
E- element type | 元素类型
- All Known Implementing Classes:
SetAlgebra.SetAlgebraImpl
public interface SetAlgebra<E>
SetAlgebra - Interface for set algebra operations
SetAlgebra - 集合代数操作接口
Provides a fluent interface for performing set algebra operations such as union, intersection, difference, and symmetric difference.
提供流式接口执行集合代数运算,如并集、交集、差集和对称差集。
Features | 主要功能:
- Union operation - 并集运算
- Intersection operation - 交集运算
- Difference operation - 差集运算
- Symmetric difference operation - 对称差集运算
- Subset and superset checking - 子集和超集检查
Usage Examples | 使用示例:
Set<String> set1 = Set.of("a", "b", "c");
SetAlgebra<String> algebra = SetAlgebra.of(set1);
Set<String> set2 = Set.of("b", "c", "d");
Set<String> union = algebra.union(set2); // [a, b, c, d]
Set<String> intersection = algebra.intersection(set2); // [b, c]
Set<String> difference = algebra.difference(set2); // [a]
Set<String> symDiff = algebra.symmetricDifference(set2); // [a, d]
Performance | 性能特性:
- Union/Intersection/Difference: O(n + m) - 并集/交集/差集: O(n + m)
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classDefault implementation of SetAlgebra. -
Method Summary
Modifier and TypeMethodDescriptiondifference(Set<?> other) Compute difference with another set (this - other).Filter elements matching a predicate.getSet()Get the underlying set.intersection(Set<?> other) Compute intersection with another set.booleanisDisjoint(Set<?> other) Check if this set is disjoint with another set.booleanisProperSubsetOf(Set<?> other) Check if this set is a proper subset of another set.booleanisProperSupersetOf(Set<?> other) Check if this set is a proper superset of another set.booleanisSubsetOf(Set<?> other) Check if this set is a subset of another set.booleanisSupersetOf(Set<?> other) Check if this set is a superset of another set.static <E> SetAlgebra<E> Create a SetAlgebra instance from a set.symmetricDifference(Set<? extends E> other) Compute symmetric difference with another set.Compute union with another set.
-
Method Details
-
of
Create a SetAlgebra instance from a set. 从集合创建 SetAlgebra 实例。- Type Parameters:
E- element type | 元素类型- Parameters:
set- the set | 集合- Returns:
- SetAlgebra instance | SetAlgebra 实例
-
getSet
-
union
-
intersection
-
difference
-
symmetricDifference
-
isSubsetOf
Check if this set is a subset of another set. 检查此集合是否为另一个集合的子集。- Parameters:
other- the other set | 另一个集合- Returns:
- true if this is a subset | 如果是子集则返回 true
-
isSupersetOf
Check if this set is a superset of another set. 检查此集合是否为另一个集合的超集。- Parameters:
other- the other set | 另一个集合- Returns:
- true if this is a superset | 如果是超集则返回 true
-
isProperSubsetOf
Check if this set is a proper subset of another set. 检查此集合是否为另一个集合的真子集。- Parameters:
other- the other set | 另一个集合- Returns:
- true if this is a proper subset | 如果是真子集则返回 true
-
isProperSupersetOf
Check if this set is a proper superset of another set. 检查此集合是否为另一个集合的真超集。- Parameters:
other- the other set | 另一个集合- Returns:
- true if this is a proper superset | 如果是真超集则返回 true
-
isDisjoint
Check if this set is disjoint with another set. 检查此集合是否与另一个集合不相交。- Parameters:
other- the other set | 另一个集合- Returns:
- true if disjoint | 如果不相交则返回 true
-
filter
-