Package org.fxmisc.richtext.util
Class SubscribeableContentsObsSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- org.fxmisc.richtext.util.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>AnObservableSetimplementation that allows one to subscribe to updates within the elements themselves. For example, if one storedTextin this set and one wanted to be notified each time one of the text'stextProperty()changed, one could useaddSubscriber(Function)with the function
When the element is removed from the set, the function's returnedtext -> { 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"); }); }Subscriptionisunsubscribedto prevent any memory leaks.
-
-
Constructor Summary
Constructors Constructor Description SubscribeableContentsObsSet()SubscribeableContentsObsSet(java.util.Comparator<? super E> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)SubscriptionaddChangeListener(javafx.collections.SetChangeListener<? super E> listener)Helper method for adding a change listener that can be removed by callingunsubscribeon the returnedSubscription.SubscriptionaddInvalidationListener(javafx.beans.InvalidationListener listener)Helper method for adding an invalidation listener that can be removed by callingunsubscribeon the returnedSubscription.voidaddListener(javafx.beans.InvalidationListener listener)voidaddListener(javafx.collections.SetChangeListener<? super E> listener)SubscriptionaddSubscriber(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 callingunsubscribeon the function's returnedSubscription.java.util.Iterator<E>iterator()booleanremove(java.lang.Object o)voidremoveListener(javafx.beans.InvalidationListener listener)voidremoveListener(javafx.collections.SetChangeListener<? super E> listener)intsize()-
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
SubscribeableContentsObsSet
public SubscribeableContentsObsSet()
-
SubscribeableContentsObsSet
public SubscribeableContentsObsSet(java.util.Comparator<? super E> comparator)
-
-
Method Detail
-
iterator
public java.util.Iterator<E> iterator()
-
size
public int size()
-
add
public boolean add(E e)
-
remove
public boolean remove(java.lang.Object o)
-
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 callingunsubscribeon the function's returnedSubscription.
-
addChangeListener
public Subscription addChangeListener(javafx.collections.SetChangeListener<? super E> listener)
Helper method for adding a change listener that can be removed by callingunsubscribeon the returnedSubscription.
-
addInvalidationListener
public Subscription addInvalidationListener(javafx.beans.InvalidationListener listener)
Helper method for adding an invalidation listener that can be removed by callingunsubscribeon the returnedSubscription.
-
addListener
public void addListener(javafx.collections.SetChangeListener<? super E> listener)
- Specified by:
addListenerin interfacejavafx.collections.ObservableSet<E>
-
removeListener
public void removeListener(javafx.collections.SetChangeListener<? super E> listener)
- Specified by:
removeListenerin interfacejavafx.collections.ObservableSet<E>
-
addListener
public void addListener(javafx.beans.InvalidationListener listener)
- Specified by:
addListenerin interfacejavafx.beans.Observable
-
removeListener
public void removeListener(javafx.beans.InvalidationListener listener)
- Specified by:
removeListenerin interfacejavafx.beans.Observable
-
-