diff options
Diffstat (limited to 'src')
-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 } } |