summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-05-27 05:13:18 +0000
committerPaul Phillips <paulp@improving.org>2009-05-27 05:13:18 +0000
commit21733eb9fd9a97c2a1ab7f7b0e313166fdeb9b6c (patch)
tree0dfa1546c3e04c33d9b5e6814ac9c8c4ee9b64db /src/library
parent9ed3fc1dbd90ae93b5bd7abe010a42196e5dee69 (diff)
downloadscala-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')
-rw-r--r--src/library/scala/collection/generic/BufferTemplate.scala2
-rw-r--r--src/library/scala/collection/generic/MutableSetTemplate.scala10
-rw-r--r--src/library/scala/collection/mutable/History.scala17
-rw-r--r--src/library/scala/collection/mutable/ObservableBuffer.scala40
-rw-r--r--src/library/scala/collection/mutable/ObservableMap.scala51
-rw-r--r--src/library/scala/collection/mutable/ObservableSet.scala15
-rw-r--r--src/library/scala/collection/mutable/Publisher.scala34
-rw-r--r--src/library/scala/collection/mutable/RevertibleHistory.scala2
-rw-r--r--src/library/scala/collection/mutable/Subscriber.scala2
-rw-r--r--src/library/scala/collection/mutable/Undoable.scala11
-rw-r--r--src/library/scala/collection/script/Message.scala2
11 files changed, 78 insertions, 108 deletions
diff --git a/src/library/scala/collection/generic/BufferTemplate.scala b/src/library/scala/collection/generic/BufferTemplate.scala
index 45112795d5..74f61870d3 100644
--- a/src/library/scala/collection/generic/BufferTemplate.scala
+++ b/src/library/scala/collection/generic/BufferTemplate.scala
@@ -208,7 +208,7 @@ trait BufferTemplate[A, +This <: BufferTemplate[A, This] with Buffer[A]]
case Remove(Index(n), x) => if (this(n) == x) remove(n)
case Remove(NoLo, x) => this -= x
- case Reset => clear
+ case Reset() => clear
case s: Script[_] => s.elements foreach <<
case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
}
diff --git a/src/library/scala/collection/generic/MutableSetTemplate.scala b/src/library/scala/collection/generic/MutableSetTemplate.scala
index f24100b81e..bd2a094c96 100644
--- a/src/library/scala/collection/generic/MutableSetTemplate.scala
+++ b/src/library/scala/collection/generic/MutableSetTemplate.scala
@@ -203,14 +203,8 @@ trait MutableSetTemplate[A, +This <: MutableSetTemplate[A, This] with mutable.Se
def <<(cmd: Message[A]): Unit = cmd match {
case Include(_, x) => this += x
case Remove(_, x) => this -= x
- case Reset => clear
+ case Reset() => clear
case s: Script[_] => s.elements foreach <<
case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
}
-}
-
-
-
-
-
-
+} \ No newline at end of file
diff --git a/src/library/scala/collection/mutable/History.scala b/src/library/scala/collection/mutable/History.scala
index e90f570c53..6f2ab4b160 100644
--- a/src/library/scala/collection/mutable/History.scala
+++ b/src/library/scala/collection/mutable/History.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -22,10 +21,9 @@ package scala.collection.mutable
* @version 1.0, 08/07/2003
*/
@serializable
-class History[A, B] extends AnyRef with Subscriber[A, B] with Collection[(B, A)] {
-
+class History[A, B] extends AnyRef with Subscriber[A, B] with Collection[(B, A)]
+{
protected val log: Queue[(B, A)] = new Queue[(B, A)]
-
val maxHistory: Int = 1000
/**
@@ -33,18 +31,15 @@ class History[A, B] extends AnyRef with Subscriber[A, B] with Collection[(B, A)]
* @param event ...
*/
def notify(pub: B, event: A): Unit = {
- if (log.length >= maxHistory) {
- val old = log.dequeue;
- }
+ if (log.length >= maxHistory)
+ log.dequeue
+
log.enqueue((pub, event))
}
+ override def size: Int = log.length
def elements: Iterator[(B, A)] = log.elements
-
def events: Iterator[A] = log.elements.map { case (_, e) => e }
- override def size: Int = log.length
-
def clear(): Unit = log.clear
}
-*/
diff --git a/src/library/scala/collection/mutable/ObservableBuffer.scala b/src/library/scala/collection/mutable/ObservableBuffer.scala
index 40e8bf3641..7cda49d2fa 100644
--- a/src/library/scala/collection/mutable/ObservableBuffer.scala
+++ b/src/library/scala/collection/mutable/ObservableBuffer.scala
@@ -1,5 +1,4 @@
-/* TODO: Reintegrate
-* /* __ *\
+/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
@@ -12,8 +11,7 @@
package scala.collection.mutable
-
-//import Predef.UnsupportedOperationException
+import script._
/** This class is typically used as a mixin. It adds a subscription
* mechanism to the <code>Buffer</code> class into which this abstract
@@ -25,42 +23,29 @@ package scala.collection.mutable
*/
trait ObservableBuffer[A, This <: ObservableBuffer[A, This]]
extends Buffer[A]
- with Publisher[Message[(Location, A)]
- with Undoable, This]
+ with Publisher[Message[A] with Undoable, This]
{ self: This =>
- abstract override def +(element: A): Buffer[A] = {
- super.+(element)
- publish(new Include((End, element)) with Undoable {
+ abstract override def +=(element: A): this.type = {
+ super.+=(element)
+ publish(new Include(End, element) with Undoable {
def undo() { trimEnd(1) }
})
this
}
- abstract override def +:(element: A): Buffer[A] = {
- super.+:(element);
- publish(new Include((Start, element)) with Undoable {
+ abstract override def +:(element: A): this.type = {
+ super.+:(element)
+ publish(new Include(Start, element) with Undoable {
def undo() { trimStart(1) }
})
this
}
- abstract override def insertAll(n: Int, iter: Iterable[A]): Unit = {
- super.insertAll(n, iter)
- var i = n
- val it = iter.elements
- while (it.hasNext) {
- publish(new Include((Index(i), it.next)) with Undoable {
- def undo { remove(i) }
- })
- i = i + 1
- }
- }
-
abstract override def update(n: Int, newelement: A): Unit = {
val oldelement = apply(n)
super.update(n, newelement)
- publish(new Update((Index(n), newelement)) with Undoable {
+ publish(new Update(Index(n), newelement) with Undoable {
def undo { update(n, oldelement) }
})
}
@@ -68,7 +53,7 @@ trait ObservableBuffer[A, This <: ObservableBuffer[A, This]]
abstract override def remove(n: Int): A = {
val oldelement = apply(n)
super.remove(n)
- publish(new Remove((Index(n), oldelement)) with Undoable {
+ publish(new Remove(Index(n), oldelement) with Undoable {
def undo { insert(n, oldelement) }
})
oldelement
@@ -80,5 +65,4 @@ trait ObservableBuffer[A, This <: ObservableBuffer[A, This]]
def undo { throw new UnsupportedOperationException("cannot undo") }
})
}
-}
-*/
+} \ No newline at end of file
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]]
})
}
}
-*/
diff --git a/src/library/scala/collection/mutable/ObservableSet.scala b/src/library/scala/collection/mutable/ObservableSet.scala
index a9408f406e..31dd10c8b9 100644
--- a/src/library/scala/collection/mutable/ObservableSet.scala
+++ b/src/library/scala/collection/mutable/ObservableSet.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -12,6 +11,7 @@
package scala.collection.mutable
+import script._
/** This class is typically used as a mixin. It adds a subscription
* mechanism to the <code>Set</code> class into which this abstract
@@ -23,8 +23,7 @@ package scala.collection.mutable
*/
trait ObservableSet[A, This <: ObservableSet[A, This]]
extends Set[A]
- with Publisher[Message[A]
- with Undoable, This]
+ with Publisher[Message[A] with Undoable, This]
{ self: This =>
abstract override def +=(elem: A): this.type = {
@@ -35,9 +34,12 @@ trait ObservableSet[A, This <: ObservableSet[A, This]]
this
}
- abstract override def -=(elem: A): Unit = if (contains(elem)) {
- super.-=(elem)
- publish(new Remove(elem) with Undoable { def undo = +=(elem) })
+ abstract override def -=(elem: A): this.type = {
+ if (contains(elem)) {
+ super.-=(elem)
+ publish(new Remove(elem) with Undoable { def undo = +=(elem) })
+ }
+ this
}
abstract override def clear(): Unit = {
@@ -47,4 +49,3 @@ trait ObservableSet[A, This <: ObservableSet[A, This]]
})
}
}
-*/
diff --git a/src/library/scala/collection/mutable/Publisher.scala b/src/library/scala/collection/mutable/Publisher.scala
index 77c9dff282..527e4f1645 100644
--- a/src/library/scala/collection/mutable/Publisher.scala
+++ b/src/library/scala/collection/mutable/Publisher.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -23,28 +22,25 @@ package scala.collection.mutable
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-trait Publisher[A, This <: Publisher[A, This]] { self: This =>
- private val filters = new HashMap[Subscriber[A, This],
- scala.collection.mutable.Set[A => Boolean]]
- with MultiMap[Subscriber[A, This], A => Boolean]
- private val suspended = new HashSet[Subscriber[A, This]]
+trait Publisher[A, This <: Publisher[A, This]] {
+ self: This =>
- def subscribe(sub: Subscriber[A, This]): Unit =
- subscribe(sub, event => true)
+ type SubThis = Subscriber[A, This]
+ type Filter = A => Boolean
- def subscribe(sub: Subscriber[A, This], filter: A => Boolean): Unit =
- filters.add(sub, filter)
-
- def suspendSubscription(sub: Subscriber[A, This]): Unit = suspended += sub
-
- def activateSubscription(sub: Subscriber[A, This]): Unit = suspended -= sub
-
- def removeSubscription(sub: Subscriber[A, This]): Unit = filters -= sub
+ private val filters = new HashMap[SubThis, Set[Filter]] with MultiMap[SubThis, Filter]
+ private val suspended = new HashSet[SubThis]
+ def subscribe(sub: SubThis): Unit = subscribe(sub, event => true)
+ def subscribe(sub: SubThis, filter: Filter): Unit = filters(sub) += filter
+ def suspendSubscription(sub: SubThis): Unit = suspended += sub
+ def activateSubscription(sub: SubThis): Unit = suspended -= sub
+ def removeSubscription(sub: SubThis): Unit = filters -= sub
def removeSubscriptions() { filters.clear }
protected def publish(event: A): Unit =
filters.keys.foreach(sub =>
- if (filters.entryExists(sub, p => p(event))) sub.notify(this, event))
-}
-*/
+ if (filters.entryExists(sub, p => p(event)))
+ sub.notify(this, event)
+ )
+} \ No newline at end of file
diff --git a/src/library/scala/collection/mutable/RevertibleHistory.scala b/src/library/scala/collection/mutable/RevertibleHistory.scala
index 6561a74c2c..7f79a74429 100644
--- a/src/library/scala/collection/mutable/RevertibleHistory.scala
+++ b/src/library/scala/collection/mutable/RevertibleHistory.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -32,4 +31,3 @@ class RevertableHistory[A <: Undoable, B] extends History[A, B] with Undoable {
old.foreach { case (sub, event) => event.undo }
}
}
-*/
diff --git a/src/library/scala/collection/mutable/Subscriber.scala b/src/library/scala/collection/mutable/Subscriber.scala
index c3d5723660..751fe12498 100644
--- a/src/library/scala/collection/mutable/Subscriber.scala
+++ b/src/library/scala/collection/mutable/Subscriber.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -24,4 +23,3 @@ package scala.collection.mutable
trait Subscriber[-A, -B] {
def notify(pub: B, event: A): Unit
}
-*/
diff --git a/src/library/scala/collection/mutable/Undoable.scala b/src/library/scala/collection/mutable/Undoable.scala
index 5e0f4b8e76..121b144359 100644
--- a/src/library/scala/collection/mutable/Undoable.scala
+++ b/src/library/scala/collection/mutable/Undoable.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -20,9 +19,7 @@ package scala.collection.mutable
* @version 1.0, 08/07/2003
*/
trait Undoable {
-
- /** Undo the last operation.
- */
- def undo()
-}
-*/
+ /** Undo the last operation.
+ */
+ def undo(): Unit
+} \ No newline at end of file
diff --git a/src/library/scala/collection/script/Message.scala b/src/library/scala/collection/script/Message.scala
index af53ee1435..670a8a426a 100644
--- a/src/library/scala/collection/script/Message.scala
+++ b/src/library/scala/collection/script/Message.scala
@@ -60,7 +60,7 @@ case class Remove[+A](location: Location, elem: A) extends Message[A] {
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-case object Reset extends Message[Nothing]
+case class Reset[+A]() extends Message[A]
/** Objects of this class represent compound messages consisting
* of a sequence of other messages.