diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-27 05:13:18 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-27 05:13:18 +0000 |
commit | 21733eb9fd9a97c2a1ab7f7b0e313166fdeb9b6c (patch) | |
tree | 0dfa1546c3e04c33d9b5e6814ac9c8c4ee9b64db /src/library/scala/collection/mutable/ObservableMap.scala | |
parent | 9ed3fc1dbd90ae93b5bd7abe010a42196e5dee69 (diff) | |
download | scala-21733eb9fd9a97c2a1ab7f7b0e313166fdeb9b6c.tar.gz scala-21733eb9fd9a97c2a1ab7f7b0e313166fdeb9b6c.tar.bz2 scala-21733eb9fd9a97c2a1ab7f7b0e313166fdeb9b6c.zip |
Not quite complete reintegration of a handful o...
Not quite complete reintegration of a handful of collection classes, but
they compile quietly and keep to themselves (of course that's always
what the neighbors say after some loner goes on a rampage, so it's not
the innocuous description it once was.)
Diffstat (limited to 'src/library/scala/collection/mutable/ObservableMap.scala')
-rw-r--r-- | src/library/scala/collection/mutable/ObservableMap.scala | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/library/scala/collection/mutable/ObservableMap.scala b/src/library/scala/collection/mutable/ObservableMap.scala index 1fd5c0dbca..b4fe6c8693 100644 --- a/src/library/scala/collection/mutable/ObservableMap.scala +++ b/src/library/scala/collection/mutable/ObservableMap.scala @@ -1,4 +1,3 @@ -/* TODO: Reintegrate /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** @@ -12,6 +11,8 @@ package scala.collection.mutable +import script._ + /** This class is typically used as a mixin. It adds a subscription * mechanism to the <code>Map</code> class into which this abstract @@ -24,30 +25,37 @@ package scala.collection.mutable */ trait ObservableMap[A, B, This <: ObservableMap[A, B, This]] extends Map[A, B] - with Publisher[Message[(A, B)] - with Undoable, This] + with Publisher[Message[(A, B)] with Undoable, This] { self: This => - abstract override def update(key: A, value: B): Unit = get(key) match { - case None => - super.update(key, value) - publish(new Include((key, value)) with Undoable { - def undo = -=(key) - }) - case Some(old) => - super.update(key, value) - publish(new Update((key, value)) with Undoable { - def undo = update(key, old) - }) + abstract override def += (kv: (A, B)): this.type = { + val (key, value) = kv + + get(key) match { + case None => + super.+=(kv) + publish(new Include((key, value)) with Undoable { + def undo = -=(key) + }) + case Some(old) => + super.+=(kv) + publish(new Update((key, value)) with Undoable { + def undo = +=((key, old)) + }) + } + this } - abstract override def -= (key: A): Unit = get(key) match { - case None => - case Some(old) => - super.-=(key) - publish(new Remove((key, old)) with Undoable { - def undo = update(key, old) - }) + abstract override def -= (key: A): this.type = { + get(key) match { + case None => + case Some(old) => + super.-=(key) + publish(new Remove((key, old)) with Undoable { + def undo = update(key, old) + }) + } + this } abstract override def clear(): Unit = { @@ -57,4 +65,3 @@ trait ObservableMap[A, B, This <: ObservableMap[A, B, This]] }) } } -*/ |