From fcbf3715187470c8568057bebb7f9577f6163e88 Mon Sep 17 00:00:00 2001 From: Aleksandar Pokopec Date: Fri, 19 Nov 2010 12:38:06 +0000 Subject: Fixes #3935. No review. --- src/library/scala/collection/immutable/ListMap.scala | 2 +- src/library/scala/collection/mutable/MutableList.scala | 11 ++++++++++- src/library/scala/collection/mutable/Queue.scala | 12 ++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala index 28d2f637db..53c99216c2 100644 --- a/src/library/scala/collection/immutable/ListMap.scala +++ b/src/library/scala/collection/immutable/ListMap.scala @@ -192,7 +192,7 @@ class ListMap[A, +B] extends Map[A, B] with MapLike[A, B, ListMap[A, B]] { // if (tail eq next) this // else new tail.Node(key, value) // } - // we use an imperative one instead: + // we use an imperative one instead (and use an auxiliary list to preserve order!): var cur: ListMap[A, B1] = this var lst: List[(A, B1)] = Nil while (cur.nonEmpty) { diff --git a/src/library/scala/collection/mutable/MutableList.scala b/src/library/scala/collection/mutable/MutableList.scala index 65c973c9ec..a81cb27cf1 100644 --- a/src/library/scala/collection/mutable/MutableList.scala +++ b/src/library/scala/collection/mutable/MutableList.scala @@ -42,7 +42,7 @@ class MutableList[A] extends LinearSeq[A] /** Returns the first element in this list */ - override def head: A = first0.head + override def head: A = if (nonEmpty) first0.head else throw new NoSuchElementException /** Returns the rest of this list */ @@ -134,3 +134,12 @@ class MutableList[A] extends LinearSeq[A] def result = this } + + +object MutableList { + +} + + + + diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala index ae6c60d1d0..9fb34b07aa 100644 --- a/src/library/scala/collection/mutable/Queue.scala +++ b/src/library/scala/collection/mutable/Queue.scala @@ -30,6 +30,14 @@ import generic._ */ @serializable @cloneable class Queue[A] extends MutableList[A] with Cloneable[Queue[A]] { + + protected def this(fst: LinkedList[A], lst: LinkedList[A], lng: Int) { + this() + first0 = fst + last0 = lst + len = lng + } + /** Adds all elements to the queue. * * @param elems the elements to add. @@ -147,10 +155,10 @@ class Queue[A] extends MutableList[A] with Cloneable[Queue[A]] { * * @return the first element. */ - def front: A = first0.elem + def front: A = head } -// !!! TODO - integrate + object Queue { def apply[A](xs: A*): Queue[A] = new Queue[A] ++= xs } -- cgit v1.2.3