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 Classes
    Modifier and Type
    Interface
    Description
    static class 
    Default implementation of SetAlgebra.
  • Method Summary

    Modifier and Type
    Method
    Description
    difference(Set<?> other)
    Compute difference with another set (this - other).
    filter(Predicate<? super E> predicate)
    Filter elements matching a predicate.
    Get the underlying set.
    intersection(Set<?> other)
    Compute intersection with another set.
    boolean
    isDisjoint(Set<?> other)
    Check if this set is disjoint with another set.
    boolean
    Check if this set is a proper subset of another set.
    boolean
    Check if this set is a proper superset of another set.
    boolean
    isSubsetOf(Set<?> other)
    Check if this set is a subset of another set.
    boolean
    isSupersetOf(Set<?> other)
    Check if this set is a superset of another set.
    static <E> SetAlgebra<E>
    of(Set<E> set)
    Create a SetAlgebra instance from a set.
    symmetricDifference(Set<? extends E> other)
    Compute symmetric difference with another set.
    union(Set<? extends E> other)
    Compute union with another set.
  • Method Details

    • of

      static <E> SetAlgebra<E> of(Set<E> set)
      Create a SetAlgebra instance from a set. 从集合创建 SetAlgebra 实例。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      set - the set | 集合
      Returns:
      SetAlgebra instance | SetAlgebra 实例
    • getSet

      Set<E> getSet()
      Get the underlying set. 获取底层集合。
      Returns:
      the set | 集合
    • union

      Set<E> union(Set<? extends E> other)
      Compute union with another set. 计算与另一个集合的并集。
      Parameters:
      other - the other set | 另一个集合
      Returns:
      union of the two sets | 两个集合的并集
    • intersection

      Set<E> intersection(Set<?> other)
      Compute intersection with another set. 计算与另一个集合的交集。
      Parameters:
      other - the other set | 另一个集合
      Returns:
      intersection of the two sets | 两个集合的交集
    • difference

      Set<E> difference(Set<?> other)
      Compute difference with another set (this - other). 计算与另一个集合的差集(this - other)。
      Parameters:
      other - the other set | 另一个集合
      Returns:
      difference of the two sets | 两个集合的差集
    • symmetricDifference

      Set<E> symmetricDifference(Set<? extends E> other)
      Compute symmetric difference with another set. 计算与另一个集合的对称差集。
      Parameters:
      other - the other set | 另一个集合
      Returns:
      symmetric difference of the two sets | 两个集合的对称差集
    • isSubsetOf

      boolean isSubsetOf(Set<?> other)
      Check if this set is a subset of another set. 检查此集合是否为另一个集合的子集。
      Parameters:
      other - the other set | 另一个集合
      Returns:
      true if this is a subset | 如果是子集则返回 true
    • isSupersetOf

      boolean isSupersetOf(Set<?> other)
      Check if this set is a superset of another set. 检查此集合是否为另一个集合的超集。
      Parameters:
      other - the other set | 另一个集合
      Returns:
      true if this is a superset | 如果是超集则返回 true
    • isProperSubsetOf

      boolean isProperSubsetOf(Set<?> other)
      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

      boolean isProperSupersetOf(Set<?> other)
      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

      boolean isDisjoint(Set<?> other)
      Check if this set is disjoint with another set. 检查此集合是否与另一个集合不相交。
      Parameters:
      other - the other set | 另一个集合
      Returns:
      true if disjoint | 如果不相交则返回 true
    • filter

      Set<E> filter(Predicate<? super E> predicate)
      Filter elements matching a predicate. 过滤匹配谓词的元素。
      Parameters:
      predicate - the predicate | 谓词
      Returns:
      filtered set | 过滤后的集合