org.reactfx.ConnectableEventSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
package org.reactfx;
import org.reactfx.util.MapHelper;
public final class ConnectableEventSource
extends EventStreamBase
implements ConnectableEventStream, ConnectableEventSink {
private MapHelper, Subscription> subscriptions = null;
@Override
public final void push(T value) {
emit(value);
}
@Override
public Subscription connectTo(EventStream extends T> input) {
if(MapHelper.containsKey(subscriptions, input)) {
throw new IllegalStateException("Already connected to event stream " + input);
}
Subscription sub = isObservingInputs() ? subscribeToInput(input) : null;
subscriptions = MapHelper.put(subscriptions, input, sub);
return () -> {
Subscription s = MapHelper.get(subscriptions, input);
subscriptions = MapHelper.remove(subscriptions, input);
if(s != null) {
s.unsubscribe();
}
};
}
@Override
protected final Subscription observeInputs() {
MapHelper.replaceAll(subscriptions, (input, sub) -> subscribeToInput(input));
return () -> MapHelper.replaceAll(subscriptions, (input, sub) -> {
sub.unsubscribe();
return null;
});
}
private final Subscription subscribeToInput(EventStream extends T> input) {
return input.subscribe(this::push);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy