summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/collection/MapLike.scala2
-rw-r--r--src/library/scala/collection/SeqLike.scala10
-rw-r--r--src/library/scala/collection/immutable/MapLike.scala5
-rw-r--r--src/library/scala/collection/immutable/MapProxy.scala1
-rw-r--r--src/library/scala/collection/mutable/BufferLike.scala70
-rw-r--r--src/library/scala/collection/mutable/HashSet.scala2
-rw-r--r--src/library/scala/collection/mutable/MapLike.scala96
-rw-r--r--src/library/scala/collection/mutable/MapLikeBase.scala37
-rw-r--r--src/library/scala/collection/mutable/MapProxy.scala10
-rw-r--r--src/library/scala/collection/mutable/SetLike.scala86
-rw-r--r--src/library/scala/collection/mutable/SynchronizedMap.scala2
-rw-r--r--src/library/scala/collection/mutable/SynchronizedSet.scala2
-rw-r--r--test/files/run/arybufgrow.scala2
-rw-r--r--test/files/run/colltest1.check24
-rw-r--r--test/files/run/colltest1.scala4
15 files changed, 160 insertions, 193 deletions
diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala
index ac3c675c14..88c2b69a10 100644
--- a/src/library/scala/collection/MapLike.scala
+++ b/src/library/scala/collection/MapLike.scala
@@ -363,7 +363,7 @@ self =>
}
} catch {
case ex: ClassCastException =>
- println("calss cast "); false
+ println("class cast "); false
}}
case _ =>
false
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala
index d9f1f5257f..c8dae3fdfa 100644
--- a/src/library/scala/collection/SeqLike.scala
+++ b/src/library/scala/collection/SeqLike.scala
@@ -865,15 +865,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self =>
* and `y` of `that`, otherwise `false`.
*/
@deprecated("use `corresponds` instead")
- def equalsWith[B](that: Seq[B])(f: (A,B) => Boolean): Boolean = {
- val i = this.iterator
- val j = that.iterator
- while (i.hasNext && j.hasNext)
- if (!f(i.next, j.next))
- return false
-
- !i.hasNext && !j.hasNext
- }
+ def equalsWith[B](that: Seq[B])(f: (A,B) => Boolean): Boolean = corresponds(that)(f)
/**
* returns a projection that can be used to call non-strict <code>filter</code>,
diff --git a/src/library/scala/collection/immutable/MapLike.scala b/src/library/scala/collection/immutable/MapLike.scala
index f669268a88..0a3a8a3645 100644
--- a/src/library/scala/collection/immutable/MapLike.scala
+++ b/src/library/scala/collection/immutable/MapLike.scala
@@ -41,8 +41,9 @@ import generic._
* @version 2.8
* @since 2.8
*/
-trait MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]] extends scala.collection.MapLike[A, B, This] {
-self =>
+trait MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]]
+ extends scala.collection.MapLike[A, B, This]
+{ self =>
import scala.collection.Traversable
diff --git a/src/library/scala/collection/immutable/MapProxy.scala b/src/library/scala/collection/immutable/MapProxy.scala
index 84775c9a82..371af042e7 100644
--- a/src/library/scala/collection/immutable/MapProxy.scala
+++ b/src/library/scala/collection/immutable/MapProxy.scala
@@ -37,6 +37,7 @@ trait MapProxy[A, +B] extends Map[A, B] with MapProxyLike[A, B, Map[A, B]]
override def + [B1 >: B](kv: (A, B1)): Map[A, B1] = newProxy(self + kv)
override def + [B1 >: B](elem1: (A, B1), elem2: (A, B1), elems: (A, B1) *) =
newProxy(self.+(elem1, elem2, elems: _*))
+
override def -(key: A) = newProxy(self - key)
override def filterKeys(p: A => Boolean) = self.filterKeys(p)
diff --git a/src/library/scala/collection/mutable/BufferLike.scala b/src/library/scala/collection/mutable/BufferLike.scala
index 93e179c380..eeed35b3e7 100644
--- a/src/library/scala/collection/mutable/BufferLike.scala
+++ b/src/library/scala/collection/mutable/BufferLike.scala
@@ -227,7 +227,7 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]]
*/
override def stringPrefix: String = "Buffer"
- /** Provide a read-only view of this byffer as a sequence
+ /** Provide a read-only view of this buffer as a sequence
* @return A sequence which refers to this buffer for all its operations.
*/
def readOnly: scala.collection.Seq[A] = toSeq
@@ -251,13 +251,31 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]]
@deprecated("use ++=: instead")
final def ++:(iter: Traversable[A]): This = ++=:(iter)
+ @deprecated("use `+=:' instead")
+ final def +:(elem: A): This = +=:(elem)
+
+ // !!! Note that the two + methods below presently still modify in place. Arguably they
+ // should be changed to create new collections, and then have BOTH @migration and
+ // @deprecation annotations, because Seq-derived classes don't implement + since
+ // most of them are covariant and + interacts badly with +'s autostringification.
+ // However the compiler right now will not warn about both annotations (see the
+ // implementation comment) so I don't think that's an option without fixing that first.
+ //
+ // In addition, I don't think BufferLike should implement Addable since it
+ // deprecates all of it, and Addable has never shipped.
+ //
+ // Alternate implementations:
+ //
+ // clone() += elem
+ // clone() += elem1 += elem2 ++= elems
+
/** Adds a single element to this collection and returns
* the collection itself.
*
* @param elem the element to add.
*/
@deprecated("Use += instead if you intend to add by side effect to an existing collection.\n"+
- "Use `clone() ++=' if you intend to create a new collection.")
+ "Use `clone() +=' if you intend to create a new collection.")
override def + (elem: A): This = { +=(elem); repr }
/** Adds two or more elements to this collection and returns
@@ -267,7 +285,7 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]]
* @param elem2 the second element to add.
* @param elems the remaining elements to add.
*/
- @deprecated("Use += instead if you intend to add by side effect to an existing collection.\n"+
+ @deprecated("Use ++= instead if you intend to add by side effect to an existing collection.\n"+
"Use `clone() ++=' if you intend to create a new collection.")
override def + (elem1: A, elem2: A, elems: A*): This = {
this += elem1 += elem2 ++= elems
@@ -283,10 +301,7 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]]
"As of 2.8, ++ always creates a new collection, even on Buffers.\n"+
"Use ++= instead if you intend to add by side effect to an existing collection.\n"
)
- override def ++(iter: Traversable[A]): This = {
- for (elem <- iter) +=(elem)
- repr
- }
+ override def ++(iter: Traversable[A]): This = clone() ++= iter
/** Adds a number of elements provided by an iterator and returns
* the collection itself.
@@ -297,19 +312,18 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]]
"As of 2.8, ++ always creates a new collection, even on Buffers.\n"+
"Use ++= instead if you intend to add by side effect to an existing collection.\n"
)
- override def ++ (iter: Iterator[A]): This = {
- for (elem <- iter) +=(elem)
- repr
- }
+ override def ++ (iter: Iterator[A]): This = clone() ++= iter
/** Removes a single element from this collection and returns
* the collection itself.
*
* @param elem the element to remove.
*/
- @deprecated("Use -= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() -=` if you intend to create a new collection.")
- override def -(elem: A): This = { -=(elem); repr }
+ @migration(2, 8,
+ "As of 2.8, - always creates a new collection, even on Buffers.\n"+
+ "Use -= instead if you intend to remove by side effect from an existing collection.\n"
+ )
+ override def -(elem: A): This = clone() -= elem
/** Removes two or more elements from this collection and returns
* the collection itself.
@@ -318,12 +332,11 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]]
* @param elem2 the second element to remove.
* @param elems the remaining elements to remove.
*/
- @deprecated("Use -= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() -=` if you intend to create a new collection.")
- override def -(elem1: A, elem2: A, elems: A*): This = {
- this -= elem1 -= elem2 --= elems
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, - always creates a new collection, even on Buffers.\n"+
+ "Use -= instead if you intend to remove by side effect from an existing collection.\n"
+ )
+ override def -(elem1: A, elem2: A, elems: A*): This = clone() -= elem1 -= elem2 --= elems
/** Removes a number of elements provided by a Traversable object and returns
* the collection itself.
@@ -332,15 +345,9 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]]
*/
@migration(2, 8,
"As of 2.8, -- always creates a new collection, even on Buffers.\n"+
- "Use --= instead if you intend to add by side effect to an existing collection.\n"
+ "Use --= instead if you intend to remove by side effect from an existing collection.\n"
)
- override def --(iter: Traversable[A]): This = {
- for (elem <- iter) -=(elem)
- repr
- }
-
- @deprecated("use `+=:' instead")
- final def +:(elem: A): This = +=:(elem)
+ override def --(iter: Traversable[A]): This = clone() --= iter
/** Removes a number of elements provided by an iterator and returns
* the collection itself.
@@ -349,10 +356,7 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]]
*/
@migration(2, 8,
"As of 2.8, -- always creates a new collection, even on Buffers.\n"+
- "Use --= instead if you intend to add by side effect to an existing collection.\n"
+ "Use --= instead if you intend to remove by side effect from an existing collection.\n"
)
- override def --(iter: Iterator[A]): This = {
- for (elem <- iter) -=(elem)
- repr
- }
+ override def --(iter: Iterator[A]): This = clone() --= iter
}
diff --git a/src/library/scala/collection/mutable/HashSet.scala b/src/library/scala/collection/mutable/HashSet.scala
index f1f2ed3274..e985e717b0 100644
--- a/src/library/scala/collection/mutable/HashSet.scala
+++ b/src/library/scala/collection/mutable/HashSet.scala
@@ -50,7 +50,7 @@ class HashSet[A] extends Set[A]
}
}
- override def clone(): Set[A] = new HashSet[A] ++= this
+ override def clone() = new HashSet[A] ++= this
private def writeObject(s: java.io.ObjectOutputStream) {
serializeTo(s)
diff --git a/src/library/scala/collection/mutable/MapLike.scala b/src/library/scala/collection/mutable/MapLike.scala
index ad350f4263..c32ab54b7a 100644
--- a/src/library/scala/collection/mutable/MapLike.scala
+++ b/src/library/scala/collection/mutable/MapLike.scala
@@ -13,6 +13,7 @@ package scala.collection
package mutable
import generic._
+import annotation.migration
/** A template trait for mutable maps of type `mutable.Map[A, B]` which
* associate keys of type `A` with values of type `B`.
@@ -51,7 +52,7 @@ import generic._
* @define Coll mutable.Map
*/
trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
- extends MapLikeBase[A, B, This]
+ extends scala.collection.MapLike[A, B, This]
with Builder[(A, B), This]
with Growable[(A, B)]
with Shrinkable[A]
@@ -108,16 +109,17 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
* @return A fresh immutable map with the binding from `key` to
* `value` added to this map.
*/
- override def updated[B1 >: B](key: A, value: B1): mutable.Map[A, B1] = this + ((key, value))
+ override def updated[B1 >: B](key: A, value: B1): Map[A, B1] = this + ((key, value))
/** Add a new key/value mapping and return the map itself.
*
* @param kv the key/value mapping to be added
*/
- @deprecated("This operation will create a new map in the future. To add an element as a side\n"+
- "effect to an existing map and return that map itself, use +=. If you do want\n"+
- "to create a fresh map, you can use `clone() +=' to avoid a @deprecated warning.")
- def + (kv: (A, B)): this.type = { update(kv._1, kv._2); this }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new map. To add an element as a\n"+
+ "side effect to an existing map and return that map itself, use +=."
+ )
+ def + [B1 >: B] (kv: (A, B1)): Map[A, B1] = clone().asInstanceOf[Map[A, B1]] += kv
/** Adds two or more key/value mappings and return the map itself.
* with the added elements.
@@ -126,11 +128,12 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
* @param elem2 the second element to add.
* @param elems the remaining elements to add.
*/
- @deprecated("This operation will create a new map in the future. To add an element as a side\n"+
- "effect to an existing map and return that map itself, use +=. If you do want to\n"+
- "create a fresh map, you can use `clone() +=` to avoid a @deprecated warning.")
- def +(elem1: (A, B), elem2: (A, B), elems: (A, B)*): this.type =
- this += elem1 += elem2 ++= elems
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new map. To add an element as a\n"+
+ "side effect to an existing map and return that map itself, use +=."
+ )
+ override def + [B1 >: B] (elem1: (A, B1), elem2: (A, B1), elems: (A, B1) *): Map[A, B1] =
+ clone().asInstanceOf[Map[A, B1]] += elem1 += elem2 ++= elems
/** Adds a number of elements provided by a traversable object
* via its `iterator` method and returns
@@ -139,10 +142,12 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
*
* @param iter the traversable object.
*/
- @deprecated("This operation will create a new map in the future. To add elements as a side\n"+
- "effect to an existing map and return that map itself, use ++=. If you do want\n"+
- "to create a fresh map, you can use `clone() ++=` to avoid a @deprecated warning.")
- def ++(iter: Traversable[(A, B)]): this.type = { for (elem <- iter) +=(elem); this }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new map. To add the elements as a\n"+
+ "side effect to an existing map and return that map itself, use ++=."
+ )
+ override def ++[B1 >: B](kvs: Traversable[(A, B1)]): Map[A, B1] =
+ clone().asInstanceOf[Map[A, B1]] ++= kvs
/** Adds a number of elements provided by an iterator
* via its `iterator` method and returns
@@ -150,10 +155,12 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
*
* @param iter the iterator
*/
- @deprecated("This operation will create a new map in the future. To add elements as a side\n"+
- "effect to an existing map and return that map itself, use ++=. If you do want\n"+
- "to create a fresh map, you can use `clone() +=` to avoid a @deprecated warning.")
- def ++(iter: Iterator[(A, B)]): this.type = { for (elem <- iter) +=(elem); this }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new map. To add the elements as a\n"+
+ "side effect to an existing map and return that map itself, use ++=."
+ )
+ override def ++[B1 >: B] (iter: Iterator[(A, B1)]): Map[A, B1] =
+ clone().asInstanceOf[Map[A, B1]] ++= iter
/** Removes a key from this map, returning the value associated previously
* with that key as an option.
@@ -176,21 +183,22 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
/** Delete a key from this map if it is present and return the map itself.
* @param key the key to be removed
*/
- @deprecated("This operation will create a new map in the future. To add elements as a side\n"+
- "effect to an existing map and return that map itself, use -=. If you do want\n"+
- "to create a fresh map, you can use `clone() -=` to avoid a @deprecated warning.")
- override def -(key: A): This = { -=(key); repr }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new map. To remove an element as a\n"+
+ "side effect to an existing map and return that map itself, use -=."
+ )
+ override def -(key: A): This = clone() -= key
/** If given key is defined in this map, remove it and return associated value as an Option.
* If key is not present return None.
* @param key the key to be removed
*/
- @deprecated("Use `remove' instead") def removeKey(key: A): Option[B] = remove(key)
+ @deprecated("Use `remove' instead") def removeKey(key: A): Option[B] = remove(key)
/** Removes all bindings from the map. After this operation has completed,
* the map will be empty.
*/
- def clear() { for ((k, v) <- this.iterator) -=(k) }
+ def clear() { keysIterator foreach -= }
/** If given key is already in this map, returns associated value
* Otherwise, computes value from given expression `op`, stores with key
@@ -232,8 +240,7 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
this
}
- override def clone(): This =
- empty ++= repr
+ override def clone(): This = empty ++= repr
/** The result when this map is used as a builder
* @return the map representation itself.
@@ -247,35 +254,32 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
* @param elem2 the second element to remove.
* @param elems the remaining elements to remove.
*/
- @deprecated("Use -= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() -=' if you intend to create a new collection.")
- override def -(elem1: A, elem2: A, elems: A*): This = {
- this -= elem1 -= elem2 --= elems
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new map. To remove an element as a\n"+
+ "side effect to an existing map and return that map itself, use -=."
+ )
+ override def -(elem1: A, elem2: A, elems: A*): This =
+ clone() -= elem1 -= elem2 --= elems
/** Removes a number of elements provided by a Traversable object and returns
* the collection itself.
*
* @param iter the Traversable object.
*/
- @deprecated("Use --= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() --=' if you intend to create a new collection.")
- override def --(iter: Traversable[A]): This = {
- for (elem <- iter) -=(elem)
- repr
- }
-
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new map. To remove the elements as a\n"+
+ "side effect to an existing map and return that map itself, use --=."
+ )
+ override def --(kvs: Traversable[A]): This = clone() --= kvs
/** Removes a number of elements provided by an iterator and returns
* the collection itself.
*
* @param iter the iterator
*/
- @deprecated("Use --= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() --=' if you intend to create a new collection.")
- override def --(iter: Iterator[A]): This = {
- for (elem <- iter) -=(elem)
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new map. To remove the elements as a\n"+
+ "side effect to an existing map and return that map itself, use --=."
+ )
+ override def --(iter: Iterator[A]): This = clone() --= iter
}
diff --git a/src/library/scala/collection/mutable/MapLikeBase.scala b/src/library/scala/collection/mutable/MapLikeBase.scala
deleted file mode 100644
index 402df79d84..0000000000
--- a/src/library/scala/collection/mutable/MapLikeBase.scala
+++ /dev/null
@@ -1,37 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2010, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.collection
-package mutable
-
-/** The reason for this class is so that we can
- * have both a generic immutable `+` with signature
- *
- * def + [B1 >: B](kv: (A, B1)): Map[A, B1]
- *
- * and a (deprecated) mutable `+` of signature
- *
- * def + (kv: (A, B)): this.type = this += kv
- *
- * The former is required to fulfill the Map contract.
- * The latter is required for backwards compatibility.
- * We can't have both methods in the same class, as that would give a double definition.
- * They are OK in different classes though, and narrowly escape a `same erasure' problem.
- * Once the deprecated + goes away we can do without class MapLikeBase.
- *
- * @author Martin Odersky
- * @version 2.8
- * @since 2.8
- */
-trait MapLikeBase[A, B, +This <: MapLikeBase[A, B, This] with Map[A, B]]
- extends scala.collection.MapLike[A, B, This] with Cloneable[This] {
- def + [B1 >: B] (kv: (A, B1)): mutable.Map[A, B1] = clone().asInstanceOf[mutable.Map[A, B1]] += kv
-}
diff --git a/src/library/scala/collection/mutable/MapProxy.scala b/src/library/scala/collection/mutable/MapProxy.scala
index 55e6eba1e3..cb768f6778 100644
--- a/src/library/scala/collection/mutable/MapProxy.scala
+++ b/src/library/scala/collection/mutable/MapProxy.scala
@@ -28,14 +28,16 @@ package mutable
trait MapProxy[A, B] extends Map[A, B] with MapProxyLike[A, B, Map[A, B]]
{
+ private def newProxy[B1 >: B](newSelf: Map[A, B1]): MapProxy[A, B1] =
+ new MapProxy[A, B1] { val self = newSelf }
+
override def repr = this
override def empty: MapProxy[A, B] = new MapProxy[A, B] { val self = MapProxy.this.self.empty }
- override def +(kv: (A, B)) = { self.update(kv._1, kv._2) ; this }
- override def + [B1 >: B] (elem1: (A, B1), elem2: (A, B1), elems: (A, B1) *) =
- { self.+(elem1, elem2, elems: _*) ; this }
+ override def + [B1 >: B] (kv: (A, B1)): Map[A, B1] = newProxy(self + kv)
+ override def + [B1 >: B] (elem1: (A, B1), elem2: (A, B1), elems: (A, B1) *) = newProxy(self.+(elem1, elem2, elems: _*))
- override def -(key: A) = { self.remove(key); this }
+ override def -(key: A) = newProxy(self - key)
override def += (kv: (A, B)) = { self += kv ; this }
override def -= (key: A) = { self -= key ; this }
diff --git a/src/library/scala/collection/mutable/SetLike.scala b/src/library/scala/collection/mutable/SetLike.scala
index c7ea037f49..f5a942b752 100644
--- a/src/library/scala/collection/mutable/SetLike.scala
+++ b/src/library/scala/collection/mutable/SetLike.scala
@@ -123,7 +123,7 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]]
*/
def clear() { foreach(-=) }
- override def clone(): mutable.Set[A] = empty ++= repr
+ override def clone(): This = empty ++= repr
/** The result when this set is used as a builder
* @return the set representation itself.
@@ -135,9 +135,11 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]]
*
* @param elem the element to add.
*/
- @deprecated("Use += instead if you intend to add by side effect to an existing collection.\n"+
- "Use `clone() +=' if you intend to create a new collection.")
- override def + (elem: A): This = { +=(elem); repr }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new set. To add an element as a\n"+
+ "side effect to an existing set and return that set itself, use +=."
+ )
+ override def + (elem: A): This = clone() += elem
/** Adds two or more elements to this collection and returns
* the collection itself.
@@ -146,45 +148,45 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]]
* @param elem2 the second element to add.
* @param elems the remaining elements to add.
*/
- @deprecated("Use += instead if you intend to add by side effect to an existing collection.\n"+
- "Use `clone() +=' if you intend to create a new collection.")
- override def + (elem1: A, elem2: A, elems: A*): This = {
- this += elem1 += elem2 ++= elems
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new set. To add the elements as a\n"+
+ "side effect to an existing set and return that set itself, use +=."
+ )
+ override def + (elem1: A, elem2: A, elems: A*): This =
+ clone() += elem1 += elem2 ++= elems
/** Adds a number of elements provided by a traversable object and returns
* either the collection itself.
*
* @param iter the iterable object.
*/
- @deprecated("Use ++= instead if you intend to add by side effect to an existing collection.\n"+
- "Use `clone() ++=' if you intend to create a new collection.")
- override def ++(iter: scala.collection.Traversable[A]): This = {
- for (elem <- iter) +=(elem)
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new set. To add the elements as a\n"+
+ "side effect to an existing set and return that set itself, use ++=."
+ )
+ override def ++(iter: scala.collection.Traversable[A]): This = clone() ++= iter
/** Adds a number of elements provided by an iterator and returns
* the collection itself.
*
* @param iter the iterator
*/
- @deprecated("Use ++= instead if you intend to add by side effect to an existing collection.\n"+
- "Use `clone() ++=' if you intend to create a new collection.")
- override def ++ (iter: Iterator[A]): This = {
- for (elem <- iter) +=(elem)
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new set. To add the elements as a\n"+
+ "side effect to an existing set and return that set itself, use ++=."
+ )
+ override def ++ (iter: Iterator[A]): This = clone() ++= iter
/** Removes a single element from this collection and returns
* the collection itself.
*
* @param elem the element to remove.
*/
- @deprecated("Use -= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() -=' if you intend to create a new collection.")
- override def -(elem: A): This = { -=(elem); repr }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new set. To remove the element as a\n"+
+ "side effect to an existing set and return that set itself, use -=."
+ )
+ override def -(elem: A): This = clone() -= elem
/** Removes two or more elements from this collection and returns
* the collection itself.
@@ -193,36 +195,34 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]]
* @param elem2 the second element to remove.
* @param elems the remaining elements to remove.
*/
- @deprecated("Use -= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() -=' if you intend to create a new collection.")
- override def -(elem1: A, elem2: A, elems: A*): This = {
- this -= elem1 -= elem2 --= elems
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new set. To remove the elements as a\n"+
+ "side effect to an existing set and return that set itself, use -=."
+ )
+ override def -(elem1: A, elem2: A, elems: A*): This =
+ clone() -= elem1 -= elem2 --= elems
/** Removes a number of elements provided by a Traversable object and returns
* the collection itself.
*
* @param iter the Traversable object.
*/
- @deprecated("Use --= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() --=' if you intend to create a new collection.")
- override def --(iter: scala.collection.Traversable[A]): This = {
- for (elem <- iter) -=(elem)
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new set. To remove the elements as a\n"+
+ "side effect to an existing set and return that set itself, use --=."
+ )
+ override def --(iter: scala.collection.Traversable[A]): This = clone() --= iter
/** Removes a number of elements provided by an iterator and returns
* the collection itself.
*
* @param iter the iterator
*/
- @deprecated("Use --= instead if you intend to remove by side effect from an existing collection.\n"+
- "Use `clone() --=' if you intend to create a new collection.")
- override def --(iter: Iterator[A]): This = {
- for (elem <- iter) -=(elem)
- repr
- }
+ @migration(2, 8,
+ "As of 2.8, this operation creates a new set. To remove the elements as a\n"+
+ "side effect to an existing set and return that set itself, use --=."
+ )
+ override def --(iter: Iterator[A]): This = clone() --= iter
/** Send a message to this scriptable object.
*
diff --git a/src/library/scala/collection/mutable/SynchronizedMap.scala b/src/library/scala/collection/mutable/SynchronizedMap.scala
index a86c71b755..dabcaa7e1c 100644
--- a/src/library/scala/collection/mutable/SynchronizedMap.scala
+++ b/src/library/scala/collection/mutable/SynchronizedMap.scala
@@ -50,7 +50,7 @@ trait SynchronizedMap[A, B] extends Map[A, B] {
override def contains(key: A): Boolean = synchronized {super.contains(key) }
override def isDefinedAt(key: A) = synchronized { super.isDefinedAt(key) }
- @deprecated("See Map.+ for explanation") override def +(kv: (A, B)): this.type = synchronized[this.type] { super.+(kv) }
+ // @deprecated("See Map.+ for explanation") override def +(kv: (A, B)): this.type = synchronized[this.type] { super.+(kv) }
// can't override -, -- same type!
// @deprecated override def -(key: A): Self = synchronized { super.-(key) }
diff --git a/src/library/scala/collection/mutable/SynchronizedSet.scala b/src/library/scala/collection/mutable/SynchronizedSet.scala
index a4832ba9f4..0f129ad2cc 100644
--- a/src/library/scala/collection/mutable/SynchronizedSet.scala
+++ b/src/library/scala/collection/mutable/SynchronizedSet.scala
@@ -103,7 +103,7 @@ trait SynchronizedSet[A] extends Set[A] {
super.<<(cmd)
}
- override def clone(): Set[A] = synchronized {
+ override def clone(): Self = synchronized {
super.clone()
}
}
diff --git a/test/files/run/arybufgrow.scala b/test/files/run/arybufgrow.scala
index 4dccd962f2..35b3233055 100644
--- a/test/files/run/arybufgrow.scala
+++ b/test/files/run/arybufgrow.scala
@@ -3,7 +3,7 @@ import scala.collection.mutable._;
object Test extends Application {
val buf = new ArrayBuffer[String];
for(val i <- List.range(0,1000)) {
- buf + "hello";
+ buf += "hello";
}
Console.println("1000 = " + buf.length);
diff --git a/test/files/run/colltest1.check b/test/files/run/colltest1.check
index 7dcf4bd1a6..a5f4ada7a3 100644
--- a/test/files/run/colltest1.check
+++ b/test/files/run/colltest1.check
@@ -95,15 +95,15 @@ ArrayBuffer(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
true
false
true
-Map(E -> E, X -> X, N -> N, T -> T, Y -> Y, J -> J, U -> U, F -> F, A -> A, M -> M, I -> I, G -> G, V -> V, Q -> Q, L -> L, B -> B, P -> P, C -> C, H -> H, W -> W, K -> K, R -> R, O -> O, D -> D, Z -> Z, S -> S)
-Map(E -> E, X -> X, N -> N, T -> T, Y -> Y, J -> J, U -> U, F -> F, A -> A, M -> M, I -> I, G -> G, V -> V, Q -> Q, L -> L, B -> B, P -> P, C -> C, H -> H, W -> W, K -> K, R -> R, O -> O, D -> D, Z -> Z, S -> S)
-Map(O -> O, W -> W, H -> H, P -> P, V -> V, G -> G, I -> I, A -> A, F -> F, U -> U, N -> N, X -> X, Z -> Z, S -> S, D -> D, K -> K, R -> R, C -> C, B -> B, L -> L, Q -> Q, M -> M, J -> J, Y -> Y, T -> T, E -> E)
-Map(O -> O, W -> W, H -> H, P -> P, V -> V, G -> G, I -> I, A -> A, F -> F, U -> U, N -> N, X -> X, Z -> Z, S -> S, D -> D, K -> K, R -> R, C -> C, B -> B, L -> L, Q -> Q, M -> M, J -> J, Y -> Y, T -> T, E -> E)
-Map(E -> E, X -> X, N -> N, T -> T, Y -> Y, J -> J, U -> U, F -> F, A -> A, M -> M, I -> I, G -> G, V -> V, Q -> Q, L -> L, B -> B, P -> P, C -> C, H -> H, W -> W, K -> K, R -> R, O -> O, D -> D, Z -> Z, S -> S)
-Map(E -> E, X -> X, N -> N, T -> T, Y -> Y, J -> J, U -> U, F -> F, A -> A, M -> M, I -> I, G -> G, V -> V, Q -> Q, L -> L, B -> B, P -> P, C -> C, H -> H, W -> W, K -> K, R -> R, O -> O, D -> D, Z -> Z, S -> S)
-Map(A -> A, B -> B, C -> C, D -> D, E -> E, F -> F, G -> G, H -> H, I -> I, J -> J, K -> K, L -> L, M -> M, N -> N, O -> O, P -> P, Q -> Q, R -> R, S -> S, T -> T, U -> U, V -> V, W -> W, X -> X, Y -> Y, Z -> Z)
-Map(A -> A, B -> B, C -> C, D -> D, E -> E, F -> F, G -> G, H -> H, I -> I, J -> J, K -> K, L -> L, M -> M, N -> N, O -> O, P -> P, Q -> Q, R -> R, S -> S, T -> T, U -> U, V -> V, W -> W, X -> X, Y -> Y, Z -> Z)
-Map(O -> O, W -> W, H -> H, P -> P, V -> V, G -> G, I -> I, A -> A, F -> F, U -> U, N -> N, X -> X, Z -> Z, S -> S, D -> D, K -> K, R -> R, C -> C, B -> B, L -> L, Q -> Q, M -> M, J -> J, Y -> Y, T -> T, E -> E)
-Map(O -> O, W -> W, H -> H, P -> P, V -> V, G -> G, I -> I, A -> A, F -> F, U -> U, N -> N, X -> X, Z -> Z, S -> S, D -> D, K -> K, R -> R, C -> C, B -> B, L -> L, Q -> Q, M -> M, J -> J, Y -> Y, T -> T, E -> E)
-Map(E -> E, X -> X, N -> N, T -> T, Y -> Y, J -> J, U -> U, F -> F, A -> A, M -> M, I -> I, G -> G, V -> V, Q -> Q, L -> L, B -> B, P -> P, C -> C, H -> H, W -> W, K -> K, R -> R, O -> O, D -> D, Z -> Z, S -> S)
-Map(E -> E, X -> X, N -> N, T -> T, Y -> Y, J -> J, U -> U, F -> F, A -> A, M -> M, I -> I, G -> G, V -> V, Q -> Q, L -> L, B -> B, P -> P, C -> C, H -> H, W -> W, K -> K, R -> R, O -> O, D -> D, Z -> Z, S -> S)
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
+List((A,A), (B,B), (C,C), (D,D), (E,E), (F,F), (G,G), (H,H), (I,I), (J,J), (K,K), (L,L), (M,M), (N,N), (O,O), (P,P), (Q,Q), (R,R), (S,S), (T,T), (U,U), (V,V), (W,W), (X,X), (Y,Y), (Z,Z))
diff --git a/test/files/run/colltest1.scala b/test/files/run/colltest1.scala
index 47b273f8ee..557282cb8d 100644
--- a/test/files/run/colltest1.scala
+++ b/test/files/run/colltest1.scala
@@ -170,7 +170,7 @@ object Test extends Application {
m += (("D" -> "D"), ("E" -> "E"), ("F" -> "F"))
m ++= List(("G" -> "G"), ("H" -> "H"), ("I" -> "I"))
m ++= ('J' to 'Z') map (x => (x.toString -> x.toString))
- println(m)
+ println(m.toList.sorted)
assert(!m.isEmpty)
assert(m.keySet forall (k => (m get k) == Some(k)))
assert(m.keySet forall (k => (m apply k) == k))
@@ -185,7 +185,7 @@ object Test extends Application {
assert(mm.isEmpty, mm)
def m3 = empty ++ m1
assert(m1 == m3)
- println(m3)
+ println(m3.toList.sorted)
val m4 = m3 filterNot { case (k, v) => k != "A" }
assert(m4.size == 1, m4)
}