Class SubscribableCollection<E>

java.lang.Object
com.google.common.collect.ForwardingObject
com.google.common.collect.ForwardingCollection<E>
nl.colorize.util.SubscribableCollection<E>
Type Parameters:
E - The type of element included in this collection.
All Implemented Interfaces:
Iterable<E>, Collection<E>

public class SubscribableCollection<E> extends com.google.common.collect.ForwardingCollection<E>
Wraps an existing collection to allow subscribers to be notified whenever elements are added to or removed from the collection.
  • Method Details

    • delegate

      protected Collection<E> delegate()
      Specified by:
      delegate in class com.google.common.collect.ForwardingCollection<E>
    • add

      public boolean add(E element)
      Specified by:
      add in interface Collection<E>
      Overrides:
      add in class com.google.common.collect.ForwardingCollection<E>
    • remove

      public boolean remove(Object element)
      Specified by:
      remove in interface Collection<E>
      Overrides:
      remove in class com.google.common.collect.ForwardingCollection<E>
    • removeAll

      public boolean removeAll(Collection<?> toRemove)
      Specified by:
      removeAll in interface Collection<E>
      Overrides:
      removeAll in class com.google.common.collect.ForwardingCollection<E>
    • retainAll

      public boolean retainAll(Collection<?> toRetain)
      Specified by:
      retainAll in interface Collection<E>
      Overrides:
      retainAll in class com.google.common.collect.ForwardingCollection<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Overrides:
      clear in class com.google.common.collect.ForwardingCollection<E>
    • iterator

      public Iterator<E> iterator()
      Returns an iterator for the elements in the underlying collection. The returned iterator will not support Iterator.remove(), even if the original collection does allow this.
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Overrides:
      iterator in class com.google.common.collect.ForwardingCollection<E>
    • getFirst

      public E getFirst()
    • flush

      public Stream<E> flush()
      Removes all elements from this collection, then returns a stream containing the elements that were just removed.
    • toString

      public String toString()
      Overrides:
      toString in class com.google.common.collect.ForwardingObject
    • wrap

      public static <E> SubscribableCollection<E> wrap(Collection<E> elements)
      Returns a new SubscribableCollection instance that wraps the specified underlying collection.
    • getAddedElements

      public Subject<E> getAddedElements()
    • getRemovedElements

      public Subject<E> getRemovedElements()