diff options
author | Martin Odersky <odersky@gmail.com> | 2009-02-05 19:25:43 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-02-05 19:25:43 +0000 |
commit | 0ecacced0347e4e3b83989a274b9de53868a3a57 (patch) | |
tree | cf5bb351b3acef82ad88862bee320b9c6e32a4c3 /src/library/scalax/collection/mutable/ArrayBuffer.scala | |
parent | 48355ee28a930f19000901d761f24ca44b324c1f (diff) | |
download | scala-0ecacced0347e4e3b83989a274b9de53868a3a57.tar.gz scala-0ecacced0347e4e3b83989a274b9de53868a3a57.tar.bz2 scala-0ecacced0347e4e3b83989a274b9de53868a3a57.zip |
added support for Strings, arrays, sets.
Diffstat (limited to 'src/library/scalax/collection/mutable/ArrayBuffer.scala')
-rw-r--r-- | src/library/scalax/collection/mutable/ArrayBuffer.scala | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/library/scalax/collection/mutable/ArrayBuffer.scala b/src/library/scalax/collection/mutable/ArrayBuffer.scala index df7f6ba758..dbdb96e004 100644 --- a/src/library/scalax/collection/mutable/ArrayBuffer.scala +++ b/src/library/scalax/collection/mutable/ArrayBuffer.scala @@ -11,6 +11,13 @@ package scalax.collection.mutable +import generic.SequenceFactory + +/* Factory object for `ArrayBuffer` class */ +object ArrayBuffer extends SequenceFactory[ArrayBuffer] { + def apply[A](args: A*): ArrayBuffer[A] = new ArrayBuffer[A] ++ args.asInstanceOf[Iterable[A]] // !@! +} + /** An implementation of the <code>Buffer</code> class using an array to * represent the assembled sequence internally. Append, update and random * access take constant time (amortized time). Prepends and removes are @@ -21,7 +28,14 @@ package scalax.collection.mutable * @version 2.8 */ @serializable -class ArrayBuffer[A] extends Buffer[A] with Builder[ArrayBuffer, A] with ResizableArray[A] { +class ArrayBuffer[A](override protected val initialSize: Int) + extends Buffer[A] + with Vector[A] + with generic.mutable.VectorTemplate[ArrayBuffer, A] + with Builder[ArrayBuffer, A] + with ResizableArray[A] { + + def this() = this(16) def clear() { reduceToSize(0) } @@ -40,14 +54,14 @@ class ArrayBuffer[A] extends Buffer[A] with Builder[ArrayBuffer, A] with Resizab * via its <code>elements</code> method. The identity of the * buffer is returned. * - * @param iter the iterable object. + * @param iter the iterfable object. * @return the updated buffer. */ - override def ++=(iter: Iterable[A]) = iter match { - case v: Vector[A] => + override def ++=(iter: collection.Iterable[A]) = iter match { + case v: Vector[_] => val n = v.length ensureSize(size0 + n) - v.copyToArray(array.asInstanceOf[Array[Any]], n) + v.copyToArray(array.asInstanceOf[scala.Array[Any]], n) case _ => super.++=(iter) } @@ -91,7 +105,7 @@ class ArrayBuffer[A] extends Buffer[A] with Builder[ArrayBuffer, A] with Resizab val len = xs.length ensureSize(size0 + len) copy(n, n + len, size0 - n) - xs.copyToArray(array.asInstanceOf[Array[Any]], n) + xs.copyToArray(array.asInstanceOf[scala.Array[Any]], n) size0 += len } |