summaryrefslogtreecommitdiff
path: root/sources/scala/collection/mutable/ObservableMap.scala
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2003-07-08 08:35:16 +0000
committerschinz <schinz@epfl.ch>2003-07-08 08:35:16 +0000
commitd2df7c9c9a02cd91d2dabaf4709ab77235df13c2 (patch)
treeace55450cd241dc937f599078b7daad9eca33f0e /sources/scala/collection/mutable/ObservableMap.scala
parent1d24dc9093b581573f5b544f9a555c2a7a16d914 (diff)
downloadscala-d2df7c9c9a02cd91d2dabaf4709ab77235df13c2.tar.gz
scala-d2df7c9c9a02cd91d2dabaf4709ab77235df13c2.tar.bz2
scala-d2df7c9c9a02cd91d2dabaf4709ab77235df13c2.zip
*** empty log message ***
Diffstat (limited to 'sources/scala/collection/mutable/ObservableMap.scala')
-rw-r--r--sources/scala/collection/mutable/ObservableMap.scala40
1 files changed, 40 insertions, 0 deletions
diff --git a/sources/scala/collection/mutable/ObservableMap.scala b/sources/scala/collection/mutable/ObservableMap.scala
new file mode 100644
index 0000000000..420a0feeaa
--- /dev/null
+++ b/sources/scala/collection/mutable/ObservableMap.scala
@@ -0,0 +1,40 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+** $Id$
+\* */
+
+package scala;
+
+
+abstract class ObservableMap[A, B, This <: ObservableMap[A, B, This]]: This
+ extends MutableMap[A, B]
+ with Publisher[ObservableUpdate[Pair[A, B]] with Undo, This] {
+
+ override def update(key: A, value: B): Unit = get(key) match {
+ case None => super.update(key, value);
+ publish(new Inclusion(Pair(key, value)) with Undo {
+ def undo = remove(key);
+ });
+ case Some(old) => super.update(key, value);
+ publish(new Modification(Pair(key, old), Pair(key, value)) with Undo {
+ def undo = update(key, old._2);
+ });
+ }
+
+ override def remove(key: A): Unit = get(key) match {
+ case None =>
+ case Some(old) => super.remove(key);
+ publish(new Removal(Pair(key, old)) with Undo {
+ def undo = update(key, old);
+ });
+ }
+
+ override def clear: Unit = {
+ super.clear;
+ publish(new Reset() with Undo { def undo = error("cannot undo"); });
+ }
+}