diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-19 12:38:09 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-19 12:38:09 +0000 |
commit | 349c8baeabaac7b59c58ada4043b7f35a94e848f (patch) | |
tree | c4e71d165450261b881fd005123b7a91b9a435da | |
parent | fcbf3715187470c8568057bebb7f9577f6163e88 (diff) | |
download | scala-349c8baeabaac7b59c58ada4043b7f35a94e848f.tar.gz scala-349c8baeabaac7b59c58ada4043b7f35a94e848f.tar.bz2 scala-349c8baeabaac7b59c58ada4043b7f35a94e848f.zip |
Better integration for mutable list and queue.
No review.x
-rw-r--r-- | src/library/scala/collection/mutable/MutableList.scala | 20 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/Queue.scala | 17 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/library/scala/collection/mutable/MutableList.scala b/src/library/scala/collection/mutable/MutableList.scala index a81cb27cf1..79c05dff11 100644 --- a/src/library/scala/collection/mutable/MutableList.scala +++ b/src/library/scala/collection/mutable/MutableList.scala @@ -26,16 +26,22 @@ import immutable.{List, Nil} * @since 1 */ @serializable @SerialVersionUID(5938451523372603072L) -class MutableList[A] extends LinearSeq[A] - with LinearSeqOptimized[A, MutableList[A]] - with Builder[A, MutableList[A]] { +class MutableList[A] +extends LinearSeq[A] + with LinearSeqOptimized[A, MutableList[A]] + with GenericTraversableTemplate[A, MutableList] + with Builder[A, MutableList[A]] +{ + override def companion: GenericCompanion[MutableList] = MutableList - override protected[this] def newBuilder = new MutableList[A] + override protected[this] def newBuilder: Builder[A, MutableList[A]] = new MutableList[A] protected var first0: LinkedList[A] = new LinkedList[A] - protected var last0: LinkedList[A] = _ // undefined if first0.isEmpty + protected var last0: LinkedList[A] = first0 protected var len: Int = 0 + def toQueue = new Queue(first0, last0, len) + /** Is the list empty? */ override def isEmpty = len == 0 @@ -136,8 +142,10 @@ class MutableList[A] extends LinearSeq[A] } -object MutableList { +object MutableList extends SeqFactory[MutableList] { + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, MutableList[A]] = new GenericCanBuildFrom[A] + def newBuilder[A]: Builder[A, MutableList[A]] = new MutableList[A] } diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala index 9fb34b07aa..d808cdf537 100644 --- a/src/library/scala/collection/mutable/Queue.scala +++ b/src/library/scala/collection/mutable/Queue.scala @@ -29,9 +29,16 @@ import generic._ * @define willNotTerminateInf */ @serializable @cloneable -class Queue[A] extends MutableList[A] with Cloneable[Queue[A]] { +class Queue[A] +extends MutableList[A] + with GenericTraversableTemplate[A, Queue] + with Cloneable[Queue[A]] +{ + override def companion: GenericCompanion[Queue] = Queue - protected def this(fst: LinkedList[A], lst: LinkedList[A], lng: Int) { + override protected[this] def newBuilder = companion.newBuilder[A] + + private[mutable] def this(fst: LinkedList[A], lst: LinkedList[A], lng: Int) { this() first0 = fst last0 = lst @@ -159,6 +166,8 @@ class Queue[A] extends MutableList[A] with Cloneable[Queue[A]] { } -object Queue { - def apply[A](xs: A*): Queue[A] = new Queue[A] ++= xs +object Queue extends SeqFactory[Queue] { + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Queue[A]] = new GenericCanBuildFrom[A] + + def newBuilder[A]: Builder[A, Queue[A]] = new MutableList[A] mapResult { _.toQueue } } |