Created
February 11, 2016 08:34
-
-
Save acmi/9814eceb39289f281123 to your computer and use it in GitHub Desktop.
simple Observable non thread safe implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.beans.InvalidationListener; | |
import javafx.beans.Observable; | |
import java.util.HashSet; | |
import java.util.Set; | |
public abstract class ObservableBase implements Observable { | |
private Set<InvalidationListener> listeners = new HashSet<>(1); | |
@Override | |
public void addListener(InvalidationListener listener) { | |
listeners.add(listener); | |
} | |
@Override | |
public void removeListener(InvalidationListener listener) { | |
listeners.remove(listener); | |
} | |
protected void fireValueChangedEvent() { | |
for (InvalidationListener listener : listeners) { | |
try { | |
listener.invalidated(this); | |
} catch (Exception e) { | |
Thread.currentThread() | |
.getUncaughtExceptionHandler() | |
.uncaughtException(Thread.currentThread(), e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment