Class SubscribeableContentsObsSet<E>

  • Type Parameters:
    E - the type of element in the set
    All Implemented Interfaces:
    Iterable<E>, Collection<E>, Set<E>, Observable, ObservableSet<E>

    public class SubscribeableContentsObsSet<E>
    extends AbstractSet<E>
    implements 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.