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>
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(Comparator<? super E> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
Subscription
addChangeListener(SetChangeListener<? super E> listener)
Helper method for adding a change listener that can be removed by callingunsubscribe
on the returnedSubscription
.Subscription
addInvalidationListener(InvalidationListener listener)
Helper method for adding an invalidation listener that can be removed by callingunsubscribe
on the returnedSubscription
.void
addListener(InvalidationListener listener)
void
addListener(SetChangeListener<? super E> listener)
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 callingunsubscribe
on the function's returnedSubscription
.Iterator<E>
iterator()
boolean
remove(Object o)
void
removeListener(InvalidationListener listener)
void
removeListener(SetChangeListener<? super E> listener)
int
size()
-
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:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
add
public boolean add(E e)
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in 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 callingunsubscribe
on the function's returnedSubscription
.
-
addChangeListener
public Subscription addChangeListener(SetChangeListener<? super E> listener)
Helper method for adding a change listener that can be removed by callingunsubscribe
on the returnedSubscription
.
-
addInvalidationListener
public Subscription addInvalidationListener(InvalidationListener listener)
Helper method for adding an invalidation listener that can be removed by callingunsubscribe
on the returnedSubscription
.
-
addListener
public void addListener(SetChangeListener<? super E> listener)
- Specified by:
addListener
in interfaceObservableSet<E>
-
removeListener
public void removeListener(SetChangeListener<? super E> listener)
- Specified by:
removeListener
in interfaceObservableSet<E>
-
addListener
public void addListener(InvalidationListener listener)
- Specified by:
addListener
in interfaceObservable
-
removeListener
public void removeListener(InvalidationListener listener)
- Specified by:
removeListener
in interfaceObservable
-
-