Class ObservableSet<E>

Type Parameters:
E - 元素类型
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>

public class ObservableSet<E> extends HashSet<E>
可观察集合,支持监听元素新增和删除事件
Since:
2024-09-01 18:29
Author:
夜雨
See Also:
  • Constructor Details

    • ObservableSet

      public ObservableSet()
  • Method Details

    • addChangeListener

      public void addChangeListener(CollectionChangeListener<E> listener)
      添加集合变更监听器
      Parameters:
      listener - 集合变更监听器
    • removeChangeListener

      public void removeChangeListener(CollectionChangeListener<E> listener)
      移除集合变更监听器
      Parameters:
      listener - 集合变更监听器
    • add

      public boolean add(E e)
      新增元素并通知监听器
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Set<E>
      Overrides:
      add in class HashSet<E>
      Parameters:
      e - 待新增元素
      Returns:
      true 表示集合发生变化
    • addAll

      public boolean addAll(Collection<? extends E> c)
      批量新增元素并逐个通知监听器
      Specified by:
      addAll in interface Collection<E>
      Specified by:
      addAll in interface Set<E>
      Overrides:
      addAll in class AbstractCollection<E>
      Parameters:
      c - 待新增元素集合
      Returns:
      true 表示集合发生变化
    • remove

      public boolean remove(Object o)
      删除指定元素并通知监听器
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface Set<E>
      Overrides:
      remove in class HashSet<E>
      Parameters:
      o - 待删除元素
      Returns:
      true 表示删除成功
    • removeAll

      public boolean removeAll(Collection<?> c)
      批量删除元素并逐个通知监听器
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface Set<E>
      Overrides:
      removeAll in class AbstractSet<E>
      Parameters:
      c - 待删除元素集合
      Returns:
      true 表示集合发生变化
    • removeIf

      public boolean removeIf(Predicate<? super E> filter)
      按条件删除元素
      Parameters:
      filter - 删除条件
      Returns:
      true 表示至少删除一个元素