Class SetView<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
cloud.opencode.base.collections.SetView<E>
Type Parameters:
E - element type | 元素类型
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>

public abstract class SetView<E> extends AbstractSet<E>
SetView - Abstract Set View for Lazy Set Operations SetView - 惰性集合运算的抽象集合视图

Provides a read-only view of set operations without creating new collections. The actual computation is deferred until iteration.

提供集合运算结果的只读视图,不创建新集合。实际计算延迟到迭代时。

Features | 主要功能:

  • Lazy computation - 惰性计算
  • Read-only view - 只读视图
  • Copy to mutable/immutable collections - 复制到可变/不可变集合

Usage Examples | 使用示例:

// Union view - 并集视图
SetView<String> union = SetUtil.union(set1, set2);

// Copy to new HashSet - 复制到新 HashSet
Set<String> copy = union.copyInto(new HashSet<>());

Performance | 性能特性:

  • Creation: O(1) - 创建: O(1)
  • Iteration: O(n) - 迭代: O(n)
  • contains(): varies by operation - contains(): 因操作而异

Security | 安全性:

  • Thread-safe: No (depends on underlying sets) - 线程安全: 否(取决于底层集合)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • copyInto

      public <S extends Set<E>> S copyInto(S set)
      Copy this view into the specified set 复制到指定集合
      Type Parameters:
      S - set type | 集合类型
      Parameters:
      set - the target set | 目标集合
      Returns:
      the set with elements added | 添加元素后的集合
    • toSet

      public Set<E> toSet()
      Copy this view to a new HashSet 复制到新的 HashSet
      Returns:
      new HashSet containing all elements | 包含所有元素的新 HashSet
    • add

      public final boolean add(E e)
      This operation is not supported on SetView SetView 不支持添加操作
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Set<E>
      Overrides:
      add in class AbstractCollection<E>
      Parameters:
      e - element to add | 要添加的元素
      Returns:
      never returns | 永不返回
      Throws:
      UnsupportedOperationException - always | 总是抛出
    • remove

      public final boolean remove(Object o)
      This operation is not supported on SetView SetView 不支持移除操作
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface Set<E>
      Overrides:
      remove in class AbstractCollection<E>
      Parameters:
      o - element to remove | 要移除的元素
      Returns:
      never returns | 永不返回
      Throws:
      UnsupportedOperationException - always | 总是抛出
    • clear

      public final void clear()
      This operation is not supported on SetView SetView 不支持清空操作
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface Set<E>
      Overrides:
      clear in class AbstractCollection<E>
      Throws:
      UnsupportedOperationException - always | 总是抛出