summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormihaylov <mihaylov@epfl.ch>2007-02-18 09:51:45 +0000
committermihaylov <mihaylov@epfl.ch>2007-02-18 09:51:45 +0000
commit6c26499a9e7c566e4de4e60d0a69193027b6e01a (patch)
treec159c9adf46b8d05ab0bce44d368263196f29536 /src
parent5585e3de50aae02794eaea0792e90cbcf52ccf12 (diff)
downloadscala-6c26499a9e7c566e4de4e60d0a69193027b6e01a.tar.gz
scala-6c26499a9e7c566e4de4e60d0a69193027b6e01a.tar.bz2
scala-6c26499a9e7c566e4de4e60d0a69193027b6e01a.zip
Fixed bug contribution #338 in mutable.Queue
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/mutable/Queue.scala36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala
index 7c34c1f2ae..7fb6878a0d 100644
--- a/src/library/scala/collection/mutable/Queue.scala
+++ b/src/library/scala/collection/mutable/Queue.scala
@@ -20,7 +20,7 @@ package scala.collection.mutable
* @author Matthias Zenger
* @version 1.1, 03/05/2004
*/
-[serializable, cloneable]
+@serializable @cloneable
class Queue[A] extends MutableList[A] {
/** Checks if the queue is empty.
@@ -107,11 +107,11 @@ class Queue[A] extends MutableList[A] {
* p yields true.
*/
def dequeueAll(p: A => Boolean): Seq[A] = {
- val res = new ArrayBuffer[A]
if (first eq null)
- res
+ Seq.empty
else {
- while (p(first.elem)) {
+ val res = new ArrayBuffer[A]
+ while ((first ne null) && p(first.elem)) {
res += first.elem
first = first.next
len = len - 1
@@ -131,19 +131,22 @@ class Queue[A] extends MutableList[A] {
}
private def extractFirst(start: LinkedList[A], p: A => Boolean): Option[LinkedList[A]] = {
- var cell = start
- while ((cell.next ne null) && !p(cell.next.elem)) {
- cell = cell.next
- }
- if (cell.next eq null)
- None
+ if (isEmpty) None
else {
- val res: Option[LinkedList[A]] = Some(cell.next)
- cell.next = cell.next.next
+ var cell = start
+ while ((cell.next ne null) && !p(cell.next.elem)) {
+ cell = cell.next
+ }
if (cell.next eq null)
- last = cell
- len = len - 1
- res
+ None
+ else {
+ val res: Option[LinkedList[A]] = Some(cell.next)
+ cell.next = cell.next.next
+ if (cell.next eq null)
+ last = cell
+ len = len - 1
+ res
+ }
}
}
@@ -176,7 +179,8 @@ class Queue[A] extends MutableList[A] {
* @throws Predef.UnsupportedOperationException
* @return never.
*/
- override def hashCode(): Int = throw new UnsupportedOperationException("unsuitable as hash key")
+ override def hashCode(): Int =
+ throw new UnsupportedOperationException("unsuitable as hash key")
/** Returns a textual representation of a queue as a string.
*