Top Description Fields Constructors Methods
org.fxmisc.richtext.util

public Class SubscribeableContentsObsSet<E>

extends AbstractSet<E>
implements ObservableSet<E>
Class Inheritance
All Implemented Interfaces
javafx.collections.ObservableSet, javafx.beans.Observable, java.util.Set, java.util.Collection, java.lang.Iterable
Type Parameters
<E>
the type of element in the set
Imports
javafx.beans.InvalidationListener, javafx.collections.ObservableSet, .SetChangeListener, org.reactfx.Subscription, java.util.AbstractSet, .ArrayList, .Comparator, .Iterator, .LinkedList, .List, .Map, .Objects, .TreeMap, java.util.function.Function

An javafx.collections.ObservableSet implementation that allows one to subscribe to updates within the elements themselves. For example, if one stored javafx.scene.text.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.

Field Summary

Modifier and TypeField and Description
private final List<SetChangeListener<? super E>>
private final List<InvalidationListener>
private final Map<E, List<Subscription>>
private final List<Function<? super E, Subscription>>

Constructor Summary

AccessConstructor and Description
public
public
SubscribeableContentsObsSet(Comparator<? super E> comparator)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(E e)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds the specified element to this set if it is not already present (optional operation).

public Subscription
addChangeListener(SetChangeListener<? super E> listener)

Helper method for adding a change listener that can be removed by calling unsubscribe on the returned Subscription.

public Subscription
addInvalidationListener(InvalidationListener listener)

Helper method for adding an invalidation listener that can be removed by calling unsubscribe on the returned Subscription.

public void
addListener(SetChangeListener<? super E> listener)

Implements javafx.collections.ObservableSet.addListener.

Add a listener to this observable set.

public void
addListener(InvalidationListener listener)

Implements javafx.beans.Observable.addListener.

Adds an InvalidationListener which will be notified whenever the Observable becomes invalid.

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 calling unsubscribe on the function's returned Subscription.

private void
private void
private void
public Iterator<E>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this set.

public boolean
remove(Object o)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Removes the specified element from this set if it is present (optional operation).

public void
removeListener(SetChangeListener<? super E> listener)

Implements javafx.collections.ObservableSet.removeListener.

Tries to removed a listener from this observable set.

public void
removeListener(InvalidationListener listener)

Implements javafx.beans.Observable.removeListener.

Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes invalid.

private void
removeSubscriber(Function<? super E, Subscription> subscriber)

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set (its cardinality).

Inherited from java.util.AbstractSet:
equalshashCoderemoveAll

Field Detail

changeListenersback to summary
private final List<SetChangeListener<? super E>> changeListeners
invalidationListenersback to summary
private final List<InvalidationListener> invalidationListeners
mapback to summary
private final Map<E, List<Subscription>> map
subscribersback to summary
private final List<Function<? super E, Subscription>> subscribers

Constructor Detail

SubscribeableContentsObsSetback to summary
public SubscribeableContentsObsSet()
SubscribeableContentsObsSetback to summary
public SubscribeableContentsObsSet(Comparator<? super E> comparator)

Method Detail

addback to summary
public boolean add(E e)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Doc from java.util.Set.add.

Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that Objects.equals(e, e2). If this set already contains the element, the call leaves the set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.

The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throw an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.

Annotations
@Override
addChangeListenerback to summary
public Subscription addChangeListener(SetChangeListener<? super E> listener)

Helper method for adding a change listener that can be removed by calling unsubscribe on the returned Subscription.

addInvalidationListenerback to summary
public Subscription addInvalidationListener(InvalidationListener listener)

Helper method for adding an invalidation listener that can be removed by calling unsubscribe on the returned Subscription.

addListenerback to summary
public void addListener(SetChangeListener<? super E> listener)

Implements javafx.collections.ObservableSet.addListener.

Doc from javafx.collections.ObservableSet.addListener.

Add a listener to this observable set.

Annotations
@Override
addListenerback to summary
public void addListener(InvalidationListener listener)

Implements javafx.beans.Observable.addListener.

Doc from javafx.beans.Observable.addListener.

Adds an InvalidationListener which will be notified whenever the Observable becomes invalid. If the same listener is added more than once, then it will be notified more than once. That is, no check is made to ensure uniqueness.

Note that the same actual InvalidationListener instance may be safely registered for different Observables.

The Observable stores a strong reference to the listener which will prevent the listener from being garbage collected and may result in a memory leak. It is recommended to either unregister a listener by calling removeListener after use or to use an instance of WeakInvalidationListener avoid this situation.

Annotations
@Override
addSubscriberback to summary
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 calling unsubscribe on the function's returned Subscription.

fireElementAddedback to summary
private void fireElementAdded(E elem)
fireElementRemovedback to summary
private void fireElementRemoved(E elem)
invalidateSetback to summary
private void invalidateSet()
iteratorback to summary
public Iterator<E> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Annotations
@Override
removeback to summary
public boolean remove(Object o)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Doc from java.util.Set.remove.

Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)

Annotations
@SuppressWarnings:unchecked
@Override
removeListenerback to summary
public void removeListener(SetChangeListener<? super E> listener)

Implements javafx.collections.ObservableSet.removeListener.

Doc from javafx.collections.ObservableSet.removeListener.

Tries to removed a listener from this observable set. If the listener is not attached to this list, nothing happens.

Annotations
@Override
removeListenerback to summary
public void removeListener(InvalidationListener listener)

Implements javafx.beans.Observable.removeListener.

Doc from javafx.beans.Observable.removeListener.

Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes invalid.

If the given listener has not been previously registered (i.e. it was never added) then this method call is a no-op. If it had been previously added then it will be removed. If it had been added more than once, then only the first occurrence will be removed.

Annotations
@Override
removeSubscriberback to summary
private void removeSubscriber(Function<? super E, Subscription> subscriber)
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Annotations
@Override