Class SubscribeableContentsObsSet<E>

  • Type Parameters:
    E - the type of element in the set
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, javafx.beans.Observable, javafx.collections.ObservableSet<E>

    public class SubscribeableContentsObsSet<E>
    extends java.util.AbstractSet<E>
    implements javafx.collections.ObservableSet<E>
    An ObservableSet implementation that allows one to subscribe to updates within the elements themselves. For example, if one stored Text in this set and one wanted to be notified each time one of the text's textProperty() changed, one could use addSubscriber(Function) with the function
    
     text -> {
         EventStream<String> textValues = EventStreams.nonNullValuesOf(text.textProperty());
         return EventStreams.combine(textValues, otherTextValuesFromSomewhereElse)
             .subscribe(tuple2 -> {
                  String quantity = tuple2.get1();
                  String unit = tuple2.get2();
                  someOtherObjectOnTheScreen.setText("Will send " + quantity + " " + unit + " to the department");
             });
     }
     
    When the element is removed from the set, the function's returned Subscription is unsubscribed to prevent any memory leaks.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E e)  
      Subscription addChangeListener​(javafx.collections.SetChangeListener<? super E> listener)
      Helper method for adding a change listener that can be removed by calling unsubscribe on the returned Subscription.
      Subscription addInvalidationListener​(javafx.beans.InvalidationListener listener)
      Helper method for adding an invalidation listener that can be removed by calling unsubscribe on the returned Subscription.
      void addListener​(javafx.beans.InvalidationListener listener)  
      void addListener​(javafx.collections.SetChangeListener<? super E> listener)  
      Subscription addSubscriber​(java.util.function.Function<? super E,​Subscription> subscriber)
      Subscribes to all current and future elements' internal changes in this set until either they are removed or this subscriber is removed by calling unsubscribe on the function's returned Subscription.
      java.util.Iterator<E> iterator()  
      boolean remove​(java.lang.Object o)  
      void removeListener​(javafx.beans.InvalidationListener listener)  
      void removeListener​(javafx.collections.SetChangeListener<? super E> listener)  
      int size()  
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, clear, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, clear, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, spliterator, toArray, toArray
    • Constructor Detail

      • SubscribeableContentsObsSet

        public SubscribeableContentsObsSet()
      • SubscribeableContentsObsSet

        public SubscribeableContentsObsSet​(java.util.Comparator<? super E> comparator)
    • Method Detail

      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • add

        public boolean add​(E e)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Set<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
      • addSubscriber

        public Subscription addSubscriber​(java.util.function.Function<? super E,​Subscription> subscriber)
        Subscribes to all current and future elements' internal changes in this set until either they are removed or this subscriber is removed by calling unsubscribe on the function's returned Subscription.
      • addChangeListener

        public Subscription addChangeListener​(javafx.collections.SetChangeListener<? super E> listener)
        Helper method for adding a change listener that can be removed by calling unsubscribe on the returned Subscription.
      • addInvalidationListener

        public Subscription addInvalidationListener​(javafx.beans.InvalidationListener listener)
        Helper method for adding an invalidation listener that can be removed by calling unsubscribe on the returned Subscription.
      • addListener

        public void addListener​(javafx.collections.SetChangeListener<? super E> listener)
        Specified by:
        addListener in interface javafx.collections.ObservableSet<E>
      • removeListener

        public void removeListener​(javafx.collections.SetChangeListener<? super E> listener)
        Specified by:
        removeListener in interface javafx.collections.ObservableSet<E>
      • addListener

        public void addListener​(javafx.beans.InvalidationListener listener)
        Specified by:
        addListener in interface javafx.beans.Observable
      • removeListener

        public void removeListener​(javafx.beans.InvalidationListener listener)
        Specified by:
        removeListener in interface javafx.beans.Observable