summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/f00f/net/irc/martyr/ForwardObservable.java
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsUpdate/src/f00f/net/irc/martyr/ForwardObservable.java')
-rw-r--r--EssentialsUpdate/src/f00f/net/irc/martyr/ForwardObservable.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/EssentialsUpdate/src/f00f/net/irc/martyr/ForwardObservable.java b/EssentialsUpdate/src/f00f/net/irc/martyr/ForwardObservable.java
new file mode 100644
index 000000000..7f4d8d89a
--- /dev/null
+++ b/EssentialsUpdate/src/f00f/net/irc/martyr/ForwardObservable.java
@@ -0,0 +1,66 @@
+package f00f.net.irc.martyr;
+
+import java.util.Observer;
+import java.util.Observable;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Does notifications in the order they are added.
+ * */
+public class ForwardObservable extends Observable
+{
+ private boolean changed = true;
+ private List<Observer> obs = new LinkedList<Observer>();
+ private final Object localMonitor = new Object();
+
+
+ public void setChanged()
+ {
+ synchronized(localMonitor)
+ {
+ changed = true;
+ }
+ }
+
+ protected void clearChanged()
+ {
+ synchronized(localMonitor)
+ {
+ changed = false;
+ }
+ }
+
+ public void addObserver( Observer o )
+ {
+ synchronized(localMonitor)
+ {
+ obs.add( o );
+ }
+ }
+
+ public void deleteObserver( Observer o )
+ {
+ synchronized(localMonitor)
+ {
+ obs.remove( o );
+ }
+ }
+
+ public void notifyObservers(Object arg)
+ {
+ synchronized(localMonitor)
+ {
+ if (!changed)
+ return;
+ clearChanged();
+
+ for (Observer ob : obs) {
+ ob.update(this, arg);
+ }
+ }
+ }
+
+
+}
+