summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-05-26 20:55:24 +0000
committerPaul Phillips <paulp@improving.org>2009-05-26 20:55:24 +0000
commit9ed3fc1dbd90ae93b5bd7abe010a42196e5dee69 (patch)
tree4c57ede7a8fc69adb170f1599ed3c29481777fab
parentd03ffa84665da17c908bd381998b559548500b83 (diff)
downloadscala-9ed3fc1dbd90ae93b5bd7abe010a42196e5dee69.tar.gz
scala-9ed3fc1dbd90ae93b5bd7abe010a42196e5dee69.tar.bz2
scala-9ed3fc1dbd90ae93b5bd7abe010a42196e5dee69.zip
Moved the script related classes from scala.col...
Moved the script related classes from scala.collection.mutable to scala.collection.script and reintegrated the Scriptable trait.
-rw-r--r--src/library/scala/collection/generic/BufferTemplate.scala48
-rw-r--r--src/library/scala/collection/generic/MutableSetTemplate.scala17
-rw-r--r--src/library/scala/collection/script/Location.scala (renamed from src/library/scala/collection/mutable/Location.scala)11
-rw-r--r--src/library/scala/collection/script/Message.scala (renamed from src/library/scala/collection/mutable/Message.scala)20
-rw-r--r--src/library/scala/collection/script/Scriptable.scala (renamed from src/library/scala/collection/mutable/Scriptable.scala)11
5 files changed, 50 insertions, 57 deletions
diff --git a/src/library/scala/collection/generic/BufferTemplate.scala b/src/library/scala/collection/generic/BufferTemplate.scala
index 62056c9f5a..45112795d5 100644
--- a/src/library/scala/collection/generic/BufferTemplate.scala
+++ b/src/library/scala/collection/generic/BufferTemplate.scala
@@ -12,6 +12,7 @@
package scala.collection.generic
import mutable.Buffer
+import script._
/** Buffers are used to create sequences of elements incrementally by
* appending, prepending, or inserting new elements. It is also
@@ -26,7 +27,7 @@ import mutable.Buffer
trait BufferTemplate[A, +This <: BufferTemplate[A, This] with Buffer[A]]
extends Growable[A]
with Shrinkable[A]
-// with Scriptable[Message[(Location, A)]]
+ with Scriptable[A]
with Addable[A, This]
with Subtractable[A, This]
with Cloneable[This]
@@ -191,33 +192,26 @@ trait BufferTemplate[A, +This <: BufferTemplate[A, This] with Buffer[A]]
/** Send a message to this scriptable object.
*
* @param cmd the message to send.
- * !!!! todo: rewrite location, msg etc with enumerations or else pack in a subpackage
- def <<(cmd: Message[(Location, A)]) {
- cmd match {
- case Include((l, elem)) => l match {
- case Start => prepend(elem)
- case End => append(elem)
- case Index(n) => insert(n, elem)
- case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
- }
- case Update((l, elem)) => l match {
- case Start => update(0, elem)
- case End => update(length - 1, elem)
- case Index(n) => update(n, elem)
- case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
- }
- case Remove((l, _)) => l match {
- case Start => remove(0)
- case End => remove(length - 1)
- case Index(n) => remove(n)
- case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
- }
- case Reset() => clear
- case s: Script[_] => s.elements foreach <<
- case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
- }
- }
*/
+ def <<(cmd: Message[A]): Unit = cmd match {
+ case Include(Start, x) => prepend(x)
+ case Include(End, x) => append(x)
+ case Include(Index(n), x) => insert(n, x)
+ case Include(NoLo, x) => this += x
+
+ case Update(Start, x) => update(0, x)
+ case Update(End, x) => update(length - 1, x)
+ case Update(Index(n), x) => update(n, x)
+
+ case Remove(Start, x) => if (this(0) == x) remove(0)
+ case Remove(End, x) => if (this(length - 1) == x) remove(length - 1)
+ case Remove(Index(n), x) => if (this(n) == x) remove(n)
+ case Remove(NoLo, x) => this -= x
+
+ case Reset => clear
+ case s: Script[_] => s.elements foreach <<
+ case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
+ }
/** Defines the prefix of the string representation.
*/
diff --git a/src/library/scala/collection/generic/MutableSetTemplate.scala b/src/library/scala/collection/generic/MutableSetTemplate.scala
index 0a3840cd3e..f24100b81e 100644
--- a/src/library/scala/collection/generic/MutableSetTemplate.scala
+++ b/src/library/scala/collection/generic/MutableSetTemplate.scala
@@ -11,6 +11,8 @@
package scala.collection.generic
+import script._
+
/** A generic template for mutable sets of elements of type A.
* To implement a concrete mutable set, you need to provide implementations of the following methods:
*
@@ -29,6 +31,7 @@ package scala.collection.generic
*/
trait MutableSetTemplate[A, +This <: MutableSetTemplate[A, This] with mutable.Set[A]]
extends SetTemplate[A, This]
+ with Scriptable[A]
with Builder[A, This]
with Growable[A]
with Shrinkable[A]
@@ -196,14 +199,14 @@ trait MutableSetTemplate[A, +This <: MutableSetTemplate[A, This] with mutable.Se
* @param cmd the message to send.
* @throws <code>Predef.UnsupportedOperationException</code>
* if the message was not understood.
+ */
def <<(cmd: Message[A]): Unit = cmd match {
- case Include(elem) => this += elem
- case Remove(elem) => this -= elem
- case Reset() => clear
- case s: Script[_] => s.elements foreach <<
- case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
- }
- */
+ case Include(_, x) => this += x
+ case Remove(_, x) => this -= x
+ case Reset => clear
+ case s: Script[_] => s.elements foreach <<
+ case _ => throw new UnsupportedOperationException("message " + cmd + " not understood")
+ }
}
diff --git a/src/library/scala/collection/mutable/Location.scala b/src/library/scala/collection/script/Location.scala
index cbe180f163..fcd283e8b6 100644
--- a/src/library/scala/collection/mutable/Location.scala
+++ b/src/library/scala/collection/script/Location.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -10,7 +9,7 @@
// $Id$
-package scala.collection.mutable
+package scala.collection.script
/** Class <code>Location</code> describes locations in messages implemented
@@ -19,13 +18,9 @@ package scala.collection.mutable
* @author Matthias Zenger
* @version 1.0, 10/05/2004
*/
-abstract class Location
-
-case object NA extends Location
+sealed abstract class Location
case object Start extends Location
-
case object End extends Location
-
+case object NoLo extends Location
case class Index(n: Int) extends Location
-*/
diff --git a/src/library/scala/collection/mutable/Message.scala b/src/library/scala/collection/script/Message.scala
index 7b5ad7b2a0..af53ee1435 100644
--- a/src/library/scala/collection/mutable/Message.scala
+++ b/src/library/scala/collection/script/Message.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -10,10 +9,10 @@
// $Id$
-package scala.collection.mutable
-
+package scala.collection.script
import Predef._
+import mutable.ArrayBuffer
/** Class <code>Message</code> represents messages that are issued by observable
* collection classes whenever a data structure is changed. Class <code>Message</code>
@@ -32,7 +31,9 @@ trait Message[+A]
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-case class Include[+I](elem: I) extends Message[I]
+case class Include[+A](location: Location, elem: A) extends Message[A] {
+ def this(elem: A) = this(NoLo, elem)
+}
/** This observable update refers to destructive modification operations
* of elements from collection classes.
@@ -40,7 +41,9 @@ case class Include[+I](elem: I) extends Message[I]
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-case class Update[+A](elem: A) extends Message[A]
+case class Update[+A](location: Location, elem: A) extends Message[A] {
+ def this(elem: A) = this(NoLo, elem)
+}
/** This observable update refers to removal operations of elements
* from collection classes.
@@ -48,14 +51,16 @@ case class Update[+A](elem: A) extends Message[A]
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-case class Remove[+A](elem: A) extends Message[A]
+case class Remove[+A](location: Location, elem: A) extends Message[A] {
+ def this(elem: A) = this(NoLo, elem)
+}
/** This command refers to reset operations.
*
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-case class Reset[+A]() extends Message[A]
+case object Reset extends Message[Nothing]
/** Objects of this class represent compound messages consisting
* of a sequence of other messages.
@@ -81,4 +86,3 @@ class Script[A] extends ArrayBuffer[Message[A]] with Message[A] {
override def hashCode(): Int =
throw new UnsupportedOperationException("scripts are not suitable as hash keys")
}
-*/
diff --git a/src/library/scala/collection/mutable/Scriptable.scala b/src/library/scala/collection/script/Scriptable.scala
index f2341d4e4f..d77a0a09c1 100644
--- a/src/library/scala/collection/mutable/Scriptable.scala
+++ b/src/library/scala/collection/script/Scriptable.scala
@@ -1,4 +1,3 @@
-/* TODO: Reintegrate
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
@@ -10,7 +9,7 @@
// $Id$
-package scala.collection.mutable
+package scala.collection.script
/** Classes that mix in the <code>Scriptable</code> class allow
@@ -20,9 +19,7 @@ package scala.collection.mutable
* @version 1.0, 09/05/2004
*/
trait Scriptable[A] {
-
- /** Send a message to this scriptable object.
- */
- def <<(cmd: A): Unit
+ /** Send a message to this scriptable object.
+ */
+ def <<(cmd: Message[A]): Unit
}
-*/