E
- the type of element in the setpublic class SubscribeableContentsObsSet<E>
extends java.util.AbstractSet<E>
implements javafx.collections.ObservableSet<E>
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.Constructor and Description |
---|
SubscribeableContentsObsSet() |
SubscribeableContentsObsSet(java.util.Comparator<? super E> comparator) |
Modifier and Type | Method and 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() |
addAll, clear, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public SubscribeableContentsObsSet()
public SubscribeableContentsObsSet(java.util.Comparator<? super E> comparator)
public java.util.Iterator<E> iterator()
public int size()
public boolean add(E e)
public boolean remove(java.lang.Object o)
public Subscription addSubscriber(java.util.function.Function<? super E,Subscription> subscriber)
unsubscribe
on the function's
returned Subscription
.public Subscription addChangeListener(javafx.collections.SetChangeListener<? super E> listener)
unsubscribe
on the returned Subscription
.public Subscription addInvalidationListener(javafx.beans.InvalidationListener listener)
unsubscribe
on the returned Subscription
.public void addListener(javafx.collections.SetChangeListener<? super E> listener)
addListener
in interface javafx.collections.ObservableSet<E>
public void removeListener(javafx.collections.SetChangeListener<? super E> listener)
removeListener
in interface javafx.collections.ObservableSet<E>
public void addListener(javafx.beans.InvalidationListener listener)
addListener
in interface javafx.beans.Observable
public void removeListener(javafx.beans.InvalidationListener listener)
removeListener
in interface javafx.beans.Observable