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:
Iterable<E>,Collection<E>,Set<E>,Observable,ObservableSet<E>
public class SubscribeableContentsObsSet<E> extends AbstractSet<E> implements 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(Comparator<? super E> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)SubscriptionaddChangeListener(SetChangeListener<? super E> listener)Helper method for adding a change listener that can be removed by callingunsubscribeon the returnedSubscription.SubscriptionaddInvalidationListener(InvalidationListener listener)Helper method for adding an invalidation listener that can be removed by callingunsubscribeon the returnedSubscription.voidaddListener(InvalidationListener listener)voidaddListener(SetChangeListener<? super E> listener)SubscriptionaddSubscriber(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.Iterator<E>iterator()booleanremove(Object o)voidremoveListener(InvalidationListener listener)voidremoveListener(SetChangeListener<? super E> listener)intsize()-
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
-
-
-
-
Constructor Detail
-
SubscribeableContentsObsSet
public SubscribeableContentsObsSet()
-
SubscribeableContentsObsSet
public SubscribeableContentsObsSet(Comparator<? super E> comparator)
-
-
Method Detail
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
add
public boolean add(E e)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
addSubscriber
public Subscription addSubscriber(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(SetChangeListener<? super E> listener)
Helper method for adding a change listener that can be removed by callingunsubscribeon the returnedSubscription.
-
addInvalidationListener
public Subscription addInvalidationListener(InvalidationListener listener)
Helper method for adding an invalidation listener that can be removed by callingunsubscribeon the returnedSubscription.
-
addListener
public void addListener(SetChangeListener<? super E> listener)
- Specified by:
addListenerin interfaceObservableSet<E>
-
removeListener
public void removeListener(SetChangeListener<? super E> listener)
- Specified by:
removeListenerin interfaceObservableSet<E>
-
addListener
public void addListener(InvalidationListener listener)
- Specified by:
addListenerin interfaceObservable
-
removeListener
public void removeListener(InvalidationListener listener)
- Specified by:
removeListenerin interfaceObservable
-
-