diff options
-rw-r--r-- | src/library/scala/List.scala | 4 | ||||
-rw-r--r-- | src/library/scala/RandomAccessSeq.scala | 3 | ||||
-rw-r--r-- | src/library/scala/Seq.scala | 3 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/Queue.scala | 29 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/Stack.scala | 25 | ||||
-rw-r--r-- | test/files/run/lists.scala | 2 |
6 files changed, 54 insertions, 12 deletions
diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala index 2bb49e652e..2486aac041 100644 --- a/src/library/scala/List.scala +++ b/src/library/scala/List.scala @@ -486,10 +486,12 @@ sealed abstract class List[+A] extends Seq[A] { * Add an element <code>x</code> at the end of this list. * </p> * + * @deprecated Replace uses of <code>l + e</code> with <code>l ::: List(e)</code>. + * * @param x the element to append. * @return the list with <code>x</code> added at the end. */ - override def +[B >: A](x: B): List[B] = + @deprecated def +[B >: A](x: B): List[B] = if (isEmpty) List(x) else { val buf = new ListBuffer[B] diff --git a/src/library/scala/RandomAccessSeq.scala b/src/library/scala/RandomAccessSeq.scala index 18b2beb0d6..437d7ae8fb 100644 --- a/src/library/scala/RandomAccessSeq.scala +++ b/src/library/scala/RandomAccessSeq.scala @@ -205,9 +205,6 @@ trait RandomAccessSeq[+A] extends Seq[A] { buf.readOnly } - override def +[B >: A](e: B): RandomAccessSeq[B] = - this ++ Seq.single(e) - override def toStream : Stream[A] = new Stream.Definite[A] { override def isEmpty = RandomAccessSeq.this.isEmpty override def head = RandomAccessSeq.this.apply(0) diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala index b49b24ebe8..d43f2d9586 100644 --- a/src/library/scala/Seq.scala +++ b/src/library/scala/Seq.scala @@ -213,9 +213,6 @@ trait Seq[+A] extends AnyRef with PartialFunction[Int, A] with Collection[A] { buf.readOnly } - def +[B >: A](e: B): Seq[B] = - this ++ Seq.single(e) - /** Is this partial function defined for the index <code>x</code>? * * @param x .. diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 01abc1a813..bb481f263a 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -70,9 +70,34 @@ class Queue[+A](elem: A*) extends Seq[A] { /** Creates a new queue with element added at the end * of the old queue. * + * @deprecated Use the method <code>enqueue</code> from now on. + * * @param elem the element to insert */ - override def +[B >: A](elem: B) = mkQueue(elem :: in, out) + @deprecated def +[B >: A](elem: B) = mkQueue(elem :: in, out) + + /** Creates a new queue with element added at the end + * of the old queue. + * + * @param elem the element to insert + */ + def enqueue[B >: A](elem: B) = mkQueue(elem :: in, out) + + /** Returns a new queue with all all elements provided by + * an <code>Iterable</code> object added at the end of + * the queue. + * The elements are prepended in the order they + * are given out by the iterator. + * + * @deprecated Use the method <code>enqueue</code> from now on. + * + * @param iter an iterable object + */ + @deprecated def +[B >: A](iter: Iterable[B]) = { + var q: List[B] = in + iter.elements.foreach(e => q = e :: q) + mkQueue(q, out) + } /** Returns a new queue with all all elements provided by * an <code>Iterable</code> object added at the end of @@ -82,7 +107,7 @@ class Queue[+A](elem: A*) extends Seq[A] { * * @param iter an iterable object */ - def +[B >: A](iter: Iterable[B]) = { + def enqueue[B >: A](iter: Iterable[B]) = { var q: List[B] = in iter.elements.foreach(e => q = e :: q) mkQueue(q, out) diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala index dcff24b51c..dfcb3823df 100644 --- a/src/library/scala/collection/immutable/Stack.scala +++ b/src/library/scala/collection/immutable/Stack.scala @@ -43,10 +43,31 @@ class Stack[+A] extends Seq[A] { /** Push an element on the stack. * + * @deprecated Use the method <code>push</code> from now on. + * * @param elem the element to push on the stack. * @return the stack with the new element on top. */ - override def +[B >: A](elem: B): Stack[B] = new Node(elem) + @deprecated def +[B >: A](elem: B): Stack[B] = new Node(elem) + + /** Push an element on the stack. + * + * @param elem the element to push on the stack. + * @return the stack with the new element on top. + */ + def push[B >: A](elem: B): Stack[B] = new Node(elem) + + /** Push all elements provided by the given iterable object onto + * the stack. The last element returned by the iterable object + * will be on top of the new stack. + * + * @deprecated Use the method <code>push</code> from now on. + * + * @param elems the iterable object. + * @return the stack with the new elements on top. + */ + @deprecated def +[B >: A](elems: Iterable[B]): Stack[B] = + elems.foldLeft(this: Stack[B]){ (stack, elem) => stack + elem } /** Push all elements provided by the given iterable object onto * the stack. The last element returned by the iterable object @@ -55,7 +76,7 @@ class Stack[+A] extends Seq[A] { * @param elems the iterable object. * @return the stack with the new elements on top. */ - def +[B >: A](elems: Iterable[B]): Stack[B] = + def push[B >: A](elems: Iterable[B]): Stack[B] = elems.foldLeft(this: Stack[B]){ (stack, elem) => stack + elem } /** Push a sequence of elements onto the stack. The last element diff --git a/test/files/run/lists.scala b/test/files/run/lists.scala index fc0fec466e..2d55563f60 100644 --- a/test/files/run/lists.scala +++ b/test/files/run/lists.scala @@ -93,7 +93,7 @@ object Test2 extends TestCase("t0468") with Assert { val xs1 = List(1, 2, 3) val xs2 = List(0) - val ys1 = xs1 + 4 + val ys1 = xs1 ::: List(4) assertEquals("check_+", List(1, 2, 3, 4), ys1) val ys2 = ys1 - 4 |