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>
AnObservableSet
implementation that allows one to subscribe to updates within the elements themselves. For example, if one storedText
in 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"); }); }
Subscription
isunsubscribed
to 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 boolean
add(E e)
Subscription
addChangeListener(javafx.collections.SetChangeListener<? super E> listener)
Helper method for adding a change listener that can be removed by callingunsubscribe
on the returnedSubscription
.Subscription
addInvalidationListener(javafx.beans.InvalidationListener listener)
Helper method for adding an invalidation listener that can be removed by callingunsubscribe
on the returnedSubscription
.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 callingunsubscribe
on the function's returnedSubscription
.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.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 callingunsubscribe
on 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 callingunsubscribe
on the returnedSubscription
.
-
addInvalidationListener
public Subscription addInvalidationListener(javafx.beans.InvalidationListener listener)
Helper method for adding an invalidation listener that can be removed by callingunsubscribe
on the returnedSubscription
.
-
addListener
public void addListener(javafx.collections.SetChangeListener<? super E> listener)
- Specified by:
addListener
in interfacejavafx.collections.ObservableSet<E>
-
removeListener
public void removeListener(javafx.collections.SetChangeListener<? super E> listener)
- Specified by:
removeListener
in interfacejavafx.collections.ObservableSet<E>
-
addListener
public void addListener(javafx.beans.InvalidationListener listener)
- Specified by:
addListener
in interfacejavafx.beans.Observable
-
removeListener
public void removeListener(javafx.beans.InvalidationListener listener)
- Specified by:
removeListener
in interfacejavafx.beans.Observable
-
-