summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/Seq.scala5
-rw-r--r--sources/scala/collection/mutable/AppendBuffer.scala4
-rw-r--r--sources/scala/collection/mutable/Buffer.scala177
-rw-r--r--sources/scala/collection/mutable/MutableList.scala4
-rw-r--r--sources/scala/collection/mutable/Queue.scala2
-rw-r--r--sources/scala/collection/mutable/Stack.scala2
-rw-r--r--sources/scala/tools/scalac/ast/parser/Parser.scala10
-rw-r--r--sources/scala/tools/scalap/Arguments.scala2
-rw-r--r--sources/scala/tools/scalap/Entity.scala2
-rw-r--r--sources/scala/tools/scalap/EntityTable.scala2
-rw-r--r--sources/scala/tools/scalap/ScalaAttribute.scala2
11 files changed, 109 insertions, 103 deletions
diff --git a/sources/scala/Seq.scala b/sources/scala/Seq.scala
index 3f86281eba..f419746335 100644
--- a/sources/scala/Seq.scala
+++ b/sources/scala/Seq.scala
@@ -49,7 +49,7 @@ trait Seq[+A] with PartialFunction[Int, A] with Iterable[A] with Similarity {
*/
override def toString() = {
val iter = elements;
- var res = "Seq(";
+ var res = stringPrefix + "(";
if (iter.hasNext) {
res = res + iter.next;
while (iter.hasNext)
@@ -58,4 +58,7 @@ trait Seq[+A] with PartialFunction[Int, A] with Iterable[A] with Similarity {
res + ")"
}
+ /** Defines the prefix of the string representation.
+ */
+ protected def stringPrefix: String = "Seq";
}
diff --git a/sources/scala/collection/mutable/AppendBuffer.scala b/sources/scala/collection/mutable/AppendBuffer.scala
index cd30a7bcdb..9d83cf5bb3 100644
--- a/sources/scala/collection/mutable/AppendBuffer.scala
+++ b/sources/scala/collection/mutable/AppendBuffer.scala
@@ -21,12 +21,12 @@ final class AppendBuffer[ A ] with Seq[ A ] {
private var len = 0;
- class MyElemList with MutableList[ Option[A] ] {
+ class MyElemList extends MutableList[ Option[A] ] {
def append( e: Option[A] ) = appendElem( e );
}
private val elemList = new MyElemList();
- class MySeqList with MutableList[ Seq[A] ] {
+ class MySeqList extends MutableList[ Seq[A] ] {
def append( seq:Seq[A] ) = appendElem( seq );
}
private val seqList = new MySeqList();
diff --git a/sources/scala/collection/mutable/Buffer.scala b/sources/scala/collection/mutable/Buffer.scala
index e04a32234a..67cd3351ec 100644
--- a/sources/scala/collection/mutable/Buffer.scala
+++ b/sources/scala/collection/mutable/Buffer.scala
@@ -11,127 +11,126 @@ package scala.collection.mutable;
/** Buffers are used to create sequences of elements incrementally by
- * appending or prepending new elements. It is also possible to
- * access and modify elements in a random access fashion via the
- * index of the element in the sequence.
+ * appending, prepending, or inserting new elements. It is also
+ * possible to access and modify elements in a random access fashion
+ * via the index of the element in the current sequence.
*
* @author Matthias Zenger
- * @version 1.0, 08/07/2003
+ * @version 1.1, 02/03/2004
*/
-class Buffer[A] with MutableList[A] {
+trait Buffer[A] with Seq[A] {
- /** Prepend an element to this list.
+ /** Append a single element to this buffer and return
+ * the identity of the buffer.
*
- * @param elem the element to prepend.
+ * @param elem the element to append.
*/
- def prepend(elem: A) = prependElem(elem);
+ def +(elem: A): Buffer[A];
- /** Appends a sequence of elements to this buffer.
+ /** Append a single element to this buffer.
*
- * @param elems the elements to append.
+ * @param elem the element to append.
*/
- def append(elems: A*) = (this += elems);
+ def +=(elem: A): Unit = this + elem;
- /** Append a single element to this buffer.
+ /** Appends a number of elements provided by an iterable object
+ * via its <code>elements</code> method. The identity of the
+ * buffer is returned.
*
- * @param elem the element to append.
+ * @param iter the iterable object.
*/
- def +=(elem: A) = appendElem(elem);
+ def ++(iter: Iterable[A]): Buffer[A] = {
+ iter.elements.foreach(e => this += e);
+ this
+ }
/** Appends a number of elements provided by an iterable object
* via its <code>elements</code> method.
*
* @param iter the iterable object.
*/
- def +=(iter: Iterable[A]) = iter.elements.foreach(e => appendElem(e));
+ def ++=(iter: Iterable[A]): Unit = this ++ iter;
- /** Replace element at index <code>n</code> with the new element
- * <code>newelem</code>.
+ /** Appends a sequence of elements to this buffer.
*
- * @param n the index of the element to replace.
- * @param newelem the new element.
+ * @param elems the elements to append.
*/
- def update(n: Int, newelem: A): Unit = {
- var elem = first;
- var i = n;
- while (i > 0) {
- elem = elem.next;
- if (elem == null)
- error("cannot update element " + n + " in Buffer");
- i = i - 1;
- }
- elem.elem = newelem;
+ def append(elems: A*): Unit = this ++ elems;
+
+ /** Appends a number of elements provided by an iterable object
+ * via its <code>elements</code> method.
+ *
+ * @param iter the iterable object.
+ */
+ def appendAll(iter: Iterable[A]): Unit = this ++ iter;
+
+ /** Prepend a single element to this buffer and return
+ * the identity of the buffer.
+ *
+ * @param elem the element to append.
+ */
+ def +:(elem: A): Buffer[A];
+
+ /** Prepends a number of elements provided by an iterable object
+ * via its <code>elements</code> method. The identity of the
+ * buffer is returned.
+ *
+ * @param iter the iterable object.
+ */
+ def ++:(iter: Iterable[A]): Buffer[A] = {
+ iter.toList.reverse.foreach(e => e +: this);
+ this
}
- /** Inserts a new element at the index <code>n</code>. Opposed to method
+ /** Prepend an element to this list.
+ *
+ * @param elem the element to prepend.
+ */
+ def prepend(elems: A*): Unit = elems ++: this;
+
+ /** Prepends a number of elements provided by an iterable object
+ * via its <code>elements</code> method. The identity of the
+ * buffer is returned.
+ *
+ * @param iter the iterable object.
+ */
+ def prependAll(elems: Iterable[A]): Unit = elems ++: this;
+
+ /** Inserts new elements at the index <code>n</code>. Opposed to method
+ * <code>update</code>, this method will not replace an element with a
+ * one. Instead, it will insert the new elements at index <code>n</code>.
+ *
+ * @param n the index where a new element will be inserted.
+ * @param elems the new elements to insert.
+ */
+ def insert(n: Int, elems: A*): Unit = insertAll(n, elems);
+
+ /** Inserts new elements at the index <code>n</code>. Opposed to method
* <code>update</code>, this method will not replace an element with a
* one. Instead, it will insert a new element at index <code>n</code>.
*
- * @param n the index where a new element will be inserted.
- * @param newelem the new element to insert.
- */
- def insert(n: Int, newelem: A): Unit = {
- if (n == 0)
- prepend(newelem);
- else if (n >= len)
- append(newelem);
- else {
- var elem = first;
- var i = n;
- while (i > 1) {
- elem = elem.next;
- if (elem == null)
- error("cannot insert element " + n + " in Buffer");
- i = i - 1;
- }
- val old = elem.next;
- elem.next = new LinkedList[A](newelem, old);
- }
- }
+ * @param n the index where a new element will be inserted.
+ * @param iter the iterable object providing all elements to insert.
+ */
+ def insertAll(n: Int, iter: Iterable[A]): Unit;
+
+ /** Replace element at index <code>n</code> with the new element
+ * <code>newelem</code>.
+ *
+ * @param n the index of the element to replace.
+ * @param newelem the new element.
+ */
+ def update(n: Int, newelem: A): Unit;
/** Removes the element on a given index position.
*
* @param n the index which refers to the element to delete.
*/
- def remove(n: Int): A = {
- val old = apply(n);
- if (n >= len)
- error("cannot remove element " + n + " in Buffer");
- if ((n == 0) && (len == 1)) {
- first = null;
- last = null;
- } else if (n == 0) {
- first = first.next;
- } else {
- var elem = first;
- var i = n;
- while (i > 1) {
- elem = elem.next;
- i = i - 1;
- }
- elem.next = elem.next.next;
- if (n == (len - 1)) {
- last = elem.next;
- }
- }
- len = len - 1;
- old;
- }
+ def remove(n: Int): A;
/** Clears the buffer contents.
*/
- def clear: Unit = reset;
-
- /** Checks if two buffers are structurally identical.
- *
- * @return true, iff both buffers contain the same sequence of elements.
- */
- override def equals(that: Any): Boolean =
- that.isInstanceOf[Buffer[A]] &&
- { val other = that.asInstanceOf[Buffer[A]];
- elements.zip(other.elements).forall {
- case Pair(thiselem, thatelem) => thiselem == thatelem;
- }};
+ def clear: Unit;
/** The hashCode method always yields an error, since it is not
* safe to use buffers as keys in hash tables.
@@ -139,4 +138,8 @@ class Buffer[A] with MutableList[A] {
* @return never.
*/
override def hashCode(): Int = error("unsuitable as hash key");
+
+ /** Defines the prefix of the string representation.
+ */
+ override protected def stringPrefix: String = "Buffer";
}
diff --git a/sources/scala/collection/mutable/MutableList.scala b/sources/scala/collection/mutable/MutableList.scala
index 0ce691ef61..1f71bd7531 100644
--- a/sources/scala/collection/mutable/MutableList.scala
+++ b/sources/scala/collection/mutable/MutableList.scala
@@ -17,7 +17,7 @@ package scala.collection.mutable;
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-class MutableList[A] with Seq[A] with PartialFunction[Int, A] {
+class MutableList[A] extends Seq[A] with PartialFunction[Int, A] {
protected var first: LinkedList[A] = null;
protected var last: LinkedList[A] = null;
@@ -60,5 +60,5 @@ class MutableList[A] with Seq[A] with PartialFunction[Int, A] {
override def toList: List[A] = if (first == null) Nil else first.toList;
- override def toString() = toList.toString();
+ override protected def stringPrefix: String = "MutableList";
}
diff --git a/sources/scala/collection/mutable/Queue.scala b/sources/scala/collection/mutable/Queue.scala
index 331b468f48..0579fb221f 100644
--- a/sources/scala/collection/mutable/Queue.scala
+++ b/sources/scala/collection/mutable/Queue.scala
@@ -16,7 +16,7 @@ package scala.collection.mutable;
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-class Queue[A] with MutableList[A] {
+class Queue[A] extends MutableList[A] {
/** Checks if the queue is empty.
*
diff --git a/sources/scala/collection/mutable/Stack.scala b/sources/scala/collection/mutable/Stack.scala
index 18bec01433..c60518b209 100644
--- a/sources/scala/collection/mutable/Stack.scala
+++ b/sources/scala/collection/mutable/Stack.scala
@@ -16,7 +16,7 @@ package scala.collection.mutable;
* @author Matthias Zenger
* @version 1.0, 08/07/2003
*/
-class Stack[A] with MutableList[A] {
+class Stack[A] extends MutableList[A] {
/** Checks if the stack is empty.
*
diff --git a/sources/scala/tools/scalac/ast/parser/Parser.scala b/sources/scala/tools/scalac/ast/parser/Parser.scala
index f3c8cfbc0d..611b7a16fb 100644
--- a/sources/scala/tools/scalac/ast/parser/Parser.scala
+++ b/sources/scala/tools/scalac/ast/parser/Parser.scala
@@ -17,7 +17,7 @@ import java.lang.{Integer, Long, Float, Double};
import scala.Iterator;
import scala.tools.scalac.util.NewArray;
import scala.collection.immutable.ListMap ;
-import scala.collection.mutable.Buffer;
+import scala.collection.mutable.ListBuffer;
package scala.tools.scalac.ast.parser {
@@ -1667,7 +1667,7 @@ class Parser(unit: Unit) {
*/
def varDefOrDcl(mods: int): Array[Tree] = {
var newmods = mods | Modifiers.MUTABLE;
- val names = new Buffer[Pair[Int, Name]];
+ val names = new ListBuffer[Pair[Int, Name]];
do {
s.nextToken();
names.append(Pair(s.pos, ident()));
@@ -1711,7 +1711,7 @@ class Parser(unit: Unit) {
constrExpr()));
} else {
var newmods = mods;
- val lhs = new Buffer[Tuple4[Int, Name, Array[Tree$AbsTypeDef], Array[Array[Tree$ValDef]]]];
+ val lhs = new ListBuffer[Tuple4[Int, Name, Array[Tree$AbsTypeDef], Array[Array[Tree$ValDef]]]];
var loop = true;
while (loop) {
lhs.append(Tuple4(s.pos, ident(),
@@ -1789,7 +1789,7 @@ class Parser(unit: Unit) {
/** ClassDef ::= Id [TypeParamClause] [ParamClause] [`:' SimpleType] ClassTemplate
*/
def classDef(mods: int): Array[Tree] = {
- val lhs = new Buffer[Tuple4[Int, Name, Array[Tree$AbsTypeDef], Array[Array[Tree$ValDef]]]];
+ val lhs = new ListBuffer[Tuple4[Int, Name, Array[Tree$AbsTypeDef], Array[Array[Tree$ValDef]]]];
do {
s.nextToken();
lhs.append(Tuple4(s.pos,
@@ -1812,7 +1812,7 @@ class Parser(unit: Unit) {
/** ObjectDef ::= Id [`:' SimpleType] ClassTemplate
*/
def objectDef(mods: int): Array[Tree] = {
- val lhs = new Buffer[Pair[Int, Name]];
+ val lhs = new ListBuffer[Pair[Int, Name]];
do {
s.nextToken();
lhs.append(Pair(s.pos, ident()));
diff --git a/sources/scala/tools/scalap/Arguments.scala b/sources/scala/tools/scalap/Arguments.scala
index 6649aa97e8..f5c736497c 100644
--- a/sources/scala/tools/scalap/Arguments.scala
+++ b/sources/scala/tools/scalap/Arguments.scala
@@ -139,7 +139,7 @@ class Arguments {
private val arguments: Map[String, String] = new HashMap;
private val prefixes: Map[String, Set[String]] = new HashMap;
private val bindings: Map[String, Map[String, String]] = new HashMap;
- private val others: Buffer[String] = new Buffer;
+ private val others: Buffer[String] = new ListBuffer;
def addOption(option: String): Unit = options += option;
diff --git a/sources/scala/tools/scalap/Entity.scala b/sources/scala/tools/scalap/Entity.scala
index ad0f381090..8d0fe750b4 100644
--- a/sources/scala/tools/scalap/Entity.scala
+++ b/sources/scala/tools/scalap/Entity.scala
@@ -145,7 +145,7 @@ class AliasSymbol(name: String, flags: Int) extends Symbol(name, flags) {
class ClassSymbol(name: String, flags: Int) extends Symbol(name, flags) {
var thistpe: Type = NoType;
var constr: Symbol = NoSymbol;
- var scope: Buffer[Symbol] = new Buffer;
+ var scope: Buffer[Symbol] = new ListBuffer;
override def fix(tpe: Type): Unit = {
thistpe = tpe;
}
diff --git a/sources/scala/tools/scalap/EntityTable.scala b/sources/scala/tools/scalap/EntityTable.scala
index 79364c1e7a..51307496f9 100644
--- a/sources/scala/tools/scalap/EntityTable.scala
+++ b/sources/scala/tools/scalap/EntityTable.scala
@@ -15,7 +15,7 @@ class EntityTable(attrib: ScalaAttribute) {
import attrib._;
val table: Array[Entity] = new Array(attrib.table.length);
- var root: Buffer[Symbol] = new Buffer;
+ var root: Buffer[Symbol] = new ListBuffer;
{
//Console.println("created table");
diff --git a/sources/scala/tools/scalap/ScalaAttribute.scala b/sources/scala/tools/scalap/ScalaAttribute.scala
index 120371d465..5b562e6a9c 100644
--- a/sources/scala/tools/scalap/ScalaAttribute.scala
+++ b/sources/scala/tools/scalap/ScalaAttribute.scala
@@ -132,7 +132,7 @@ class ScalaAttribute(in: ByteArrayReader) {
SymbolInfo(in.nextNat, in.nextNat, in.nextNat, in.nextNat);
def readRefs(end: Int): List[Int] = {
- var res = new Buffer[Int];
+ var res = new ListBuffer[Int];
while (in.bp < end)
res += in.nextNat;
res.toList