From c2903d6ebc4ffb37c0e2179df87798813db3c695 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Thu, 17 Jan 2013 20:20:17 +0100 Subject: SI-6811 Remove scala.collection.mutable.ConcurrentMap --- src/library/scala/collection/JavaConversions.scala | 1 - src/library/scala/collection/JavaConverters.scala | 2 +- .../scala/collection/convert/DecorateAsJava.scala | 22 +----- .../scala/collection/convert/DecorateAsScala.scala | 19 ----- .../scala/collection/convert/WrapAsJava.scala | 21 ----- .../scala/collection/convert/WrapAsScala.scala | 44 +---------- .../scala/collection/convert/Wrappers.scala | 47 ----------- .../scala/collection/mutable/ConcurrentMap.scala | 90 ---------------------- .../files/neg/javaConversions-2.10-ambiguity.check | 6 -- .../files/neg/javaConversions-2.10-ambiguity.scala | 10 --- .../files/pos/javaConversions-2.10-ambiguity.scala | 10 +++ .../pos/javaConversions-2.10-regression.scala | 6 +- test/files/run/map_java_conversions.scala | 2 +- 13 files changed, 17 insertions(+), 263 deletions(-) delete mode 100644 src/library/scala/collection/mutable/ConcurrentMap.scala delete mode 100644 test/files/neg/javaConversions-2.10-ambiguity.check delete mode 100644 test/files/neg/javaConversions-2.10-ambiguity.scala create mode 100644 test/files/pos/javaConversions-2.10-ambiguity.scala diff --git a/src/library/scala/collection/JavaConversions.scala b/src/library/scala/collection/JavaConversions.scala index 7ff29650fa..3cb7edacd6 100644 --- a/src/library/scala/collection/JavaConversions.scala +++ b/src/library/scala/collection/JavaConversions.scala @@ -21,7 +21,6 @@ import convert._ * scala.collection.mutable.Buffer <=> java.util.List * scala.collection.mutable.Set <=> java.util.Set * scala.collection.mutable.Map <=> java.util.{ Map, Dictionary } - * scala.collection.mutable.ConcurrentMap (deprecated since 2.10) <=> java.util.concurrent.ConcurrentMap * scala.collection.concurrent.Map <=> java.util.concurrent.ConcurrentMap *}}} * In all cases, converting from a source type to a target type and back diff --git a/src/library/scala/collection/JavaConverters.scala b/src/library/scala/collection/JavaConverters.scala index 439991708e..7700d90560 100755 --- a/src/library/scala/collection/JavaConverters.scala +++ b/src/library/scala/collection/JavaConverters.scala @@ -24,7 +24,7 @@ import convert._ * - `scala.collection.mutable.Buffer` <=> `java.util.List` * - `scala.collection.mutable.Set` <=> `java.util.Set` * - `scala.collection.mutable.Map` <=> `java.util.Map` - * - `scala.collection.mutable.ConcurrentMap` <=> `java.util.concurrent.ConcurrentMap` + * - `scala.collection.mutable.concurrent.Map` <=> `java.util.concurrent.ConcurrentMap` * * In all cases, converting from a source type to a target type and back * again will return the original source object, e.g. diff --git a/src/library/scala/collection/convert/DecorateAsJava.scala b/src/library/scala/collection/convert/DecorateAsJava.scala index 87bcae3923..7447c1bbaf 100644 --- a/src/library/scala/collection/convert/DecorateAsJava.scala +++ b/src/library/scala/collection/convert/DecorateAsJava.scala @@ -25,7 +25,7 @@ import scala.language.implicitConversions * - `scala.collection.mutable.Buffer` <=> `java.util.List` * - `scala.collection.mutable.Set` <=> `java.util.Set` * - `scala.collection.mutable.Map` <=> `java.util.Map` - * - `scala.collection.mutable.ConcurrentMap` <=> `java.util.concurrent.ConcurrentMap` + * - `scala.collection.mutable.concurrent.Map` <=> `java.util.concurrent.ConcurrentMap` * * In all cases, converting from a source type to a target type and back * again will return the original source object, e.g. @@ -277,26 +277,6 @@ trait DecorateAsJava { implicit def mapAsJavaMapConverter[A, B](m : Map[A, B]): AsJava[ju.Map[A, B]] = new AsJava(mapAsJavaMap(m)) - /** - * Adds an `asJava` method that implicitly converts a Scala mutable - * `ConcurrentMap` to a Java `ConcurrentMap`. - * - * The returned Java `ConcurrentMap` is backed by the provided Scala - * `ConcurrentMap` and any side-effects of using it via the Java interface - * will be visible via the Scala interface and vice versa. - * - * If the Scala `ConcurrentMap` was previously obtained from an implicit or - * explicit call of `asConcurrentMap(java.util.concurrect.ConcurrentMap)` - * then the original Java `ConcurrentMap` will be returned. - * - * @param m The `ConcurrentMap` to be converted. - * @return An object with an `asJava` method that returns a Java - * `ConcurrentMap` view of the argument. - */ - @deprecated("Use `concurrent.Map` instead of `ConcurrentMap`.", "2.10.0") - implicit def asJavaConcurrentMapConverter[A, B](m: mutable.ConcurrentMap[A, B]): AsJava[juc.ConcurrentMap[A, B]] = - new AsJava(asJavaConcurrentMap(m)) - /** * Adds an `asJava` method that implicitly converts a Scala mutable * `concurrent.Map` to a Java `ConcurrentMap`. diff --git a/src/library/scala/collection/convert/DecorateAsScala.scala b/src/library/scala/collection/convert/DecorateAsScala.scala index 94847a76e3..90e8dded6e 100644 --- a/src/library/scala/collection/convert/DecorateAsScala.scala +++ b/src/library/scala/collection/convert/DecorateAsScala.scala @@ -142,25 +142,6 @@ trait DecorateAsScala { implicit def mapAsScalaMapConverter[A, B](m : ju.Map[A, B]): AsScala[mutable.Map[A, B]] = new AsScala(mapAsScalaMap(m)) - /** - * Adds an `asScala` method that implicitly converts a Java `ConcurrentMap` - * to a Scala mutable `ConcurrentMap`. The returned Scala `ConcurrentMap` is - * backed by the provided Java `ConcurrentMap` and any side-effects of using - * it via the Scala interface will be visible via the Java interface and - * vice versa. - * - * If the Java `ConcurrentMap` was previously obtained from an implicit or - * explicit call of `asConcurrentMap(scala.collection.mutable.ConcurrentMap)` - * then the original Scala `ConcurrentMap` will be returned. - * - * @param m The `ConcurrentMap` to be converted. - * @return An object with an `asScala` method that returns a Scala mutable - * `ConcurrentMap` view of the argument. - */ - @deprecated("Use `mapAsScalaConcurrentMapConverter` instead, and use `concurrent.Map` instead of `ConcurrentMap`.", "2.10.0") - def asScalaConcurrentMapConverter[A, B](m: juc.ConcurrentMap[A, B]): AsScala[mutable.ConcurrentMap[A, B]] = - new AsScala(asScalaConcurrentMap(m)) - /** * Adds an `asScala` method that implicitly converts a Java `ConcurrentMap` * to a Scala mutable `concurrent.Map`. The returned Scala `concurrent.Map` is diff --git a/src/library/scala/collection/convert/WrapAsJava.scala b/src/library/scala/collection/convert/WrapAsJava.scala index 5e6126a7cf..9665ffa045 100644 --- a/src/library/scala/collection/convert/WrapAsJava.scala +++ b/src/library/scala/collection/convert/WrapAsJava.scala @@ -234,27 +234,6 @@ trait WrapAsJava { case _ => new MapWrapper(m) } - /** - * Implicitly converts a Scala mutable `ConcurrentMap` to a Java - * `ConcurrentMap`. - * - * The returned Java `ConcurrentMap` is backed by the provided Scala - * `ConcurrentMap` and any side-effects of using it via the Java interface - * will be visible via the Scala interface and vice versa. - * - * If the Scala `ConcurrentMap` was previously obtained from an implicit or - * explicit call of `asScalaConcurrentMap(java.util.concurrect.ConcurrentMap)` - * then the original Java ConcurrentMap will be returned. - * - * @param m The `ConcurrentMap` to be converted. - * @return A Java `ConcurrentMap` view of the argument. - */ - @deprecated("Use `concurrent.Map` instead of `ConcurrentMap`.", "2.10.0") - implicit def asJavaConcurrentMap[A, B](m: mutable.ConcurrentMap[A, B]): juc.ConcurrentMap[A, B] = m match { - case JConcurrentMapDeprecatedWrapper(wrapped) => wrapped - case _ => new ConcurrentMapDeprecatedWrapper(m) - } - /** * Implicitly converts a Scala mutable `concurrent.Map` to a Java * `ConcurrentMap`. diff --git a/src/library/scala/collection/convert/WrapAsScala.scala b/src/library/scala/collection/convert/WrapAsScala.scala index ffcca62291..f43eae10d6 100644 --- a/src/library/scala/collection/convert/WrapAsScala.scala +++ b/src/library/scala/collection/convert/WrapAsScala.scala @@ -12,30 +12,7 @@ package convert import java.{ lang => jl, util => ju }, java.util.{ concurrent => juc } import scala.language.implicitConversions -trait LowPriorityWrapAsScala { - this: WrapAsScala => - - import Wrappers._ - - /** - * Implicitly converts a Java ConcurrentMap to a Scala mutable ConcurrentMap. - * The returned Scala ConcurrentMap is backed by the provided Java - * ConcurrentMap and any side-effects of using it via the Scala interface will - * be visible via the Java interface and vice versa. - * - * If the Java ConcurrentMap was previously obtained from an implicit or - * explicit call of `asConcurrentMap(scala.collection.mutable.ConcurrentMap)` - * then the original Scala ConcurrentMap will be returned. - * - * @param m The ConcurrentMap to be converted. - * @return A Scala mutable ConcurrentMap view of the argument. - */ - @deprecated("Use `mapAsScalaConcurrentMap` instead, and use `concurrent.Map` instead of `ConcurrentMap`.", "2.10.0") - implicit def mapAsScalaDeprecatedConcurrentMap[A, B](m: juc.ConcurrentMap[A, B]): mutable.ConcurrentMap[A, B] = - asScalaConcurrentMap(m) -} - -trait WrapAsScala extends LowPriorityWrapAsScala { +trait WrapAsScala { import Wrappers._ /** * Implicitly converts a Java `Iterator` to a Scala `Iterator`. @@ -165,25 +142,6 @@ trait WrapAsScala extends LowPriorityWrapAsScala { case _ => new JMapWrapper(m) } - /** - * Implicitly converts a Java ConcurrentMap to a Scala mutable ConcurrentMap. - * The returned Scala ConcurrentMap is backed by the provided Java - * ConcurrentMap and any side-effects of using it via the Scala interface will - * be visible via the Java interface and vice versa. - * - * If the Java ConcurrentMap was previously obtained from an implicit or - * explicit call of `asConcurrentMap(scala.collection.mutable.ConcurrentMap)` - * then the original Scala ConcurrentMap will be returned. - * - * @param m The ConcurrentMap to be converted. - * @return A Scala mutable ConcurrentMap view of the argument. - */ - @deprecated("Use `mapAsScalaConcurrentMap` instead, and use `concurrent.Map` instead of `ConcurrentMap`.", "2.10.0") - def asScalaConcurrentMap[A, B](m: juc.ConcurrentMap[A, B]): mutable.ConcurrentMap[A, B] = m match { - case cmw: ConcurrentMapDeprecatedWrapper[a, b] => cmw.underlying - case _ => new JConcurrentMapDeprecatedWrapper(m) - } - /** * Implicitly converts a Java ConcurrentMap to a Scala mutable ConcurrentMap. * The returned Scala ConcurrentMap is backed by the provided Java diff --git a/src/library/scala/collection/convert/Wrappers.scala b/src/library/scala/collection/convert/Wrappers.scala index 20add3365d..0f4506b5d5 100644 --- a/src/library/scala/collection/convert/Wrappers.scala +++ b/src/library/scala/collection/convert/Wrappers.scala @@ -276,28 +276,6 @@ private[collection] trait Wrappers { override def empty = JMapWrapper(new ju.HashMap[A, B]) } - class ConcurrentMapDeprecatedWrapper[A, B](override val underlying: mutable.ConcurrentMap[A, B]) extends MutableMapWrapper[A, B](underlying) with juc.ConcurrentMap[A, B] { - - def putIfAbsent(k: A, v: B) = underlying.putIfAbsent(k, v) match { - case Some(v) => v - case None => null.asInstanceOf[B] - } - - def remove(k: AnyRef, v: AnyRef) = try { - underlying.remove(k.asInstanceOf[A], v.asInstanceOf[B]) - } catch { - case ex: ClassCastException => - false - } - - def replace(k: A, v: B): B = underlying.replace(k, v) match { - case Some(v) => v - case None => null.asInstanceOf[B] - } - - def replace(k: A, oldval: B, newval: B) = underlying.replace(k, oldval, newval) - } - class ConcurrentMapWrapper[A, B](override val underlying: concurrent.Map[A, B]) extends MutableMapWrapper[A, B](underlying) with juc.ConcurrentMap[A, B] { def putIfAbsent(k: A, v: B) = underlying.putIfAbsent(k, v) match { @@ -320,31 +298,6 @@ private[collection] trait Wrappers { def replace(k: A, oldval: B, newval: B) = underlying.replace(k, oldval, newval) } - case class JConcurrentMapDeprecatedWrapper[A, B](val underlying: juc.ConcurrentMap[A, B]) extends mutable.AbstractMap[A, B] with JMapWrapperLike[A, B, JConcurrentMapDeprecatedWrapper[A, B]] with mutable.ConcurrentMap[A, B] { - override def get(k: A) = { - val v = underlying get k - if (v != null) Some(v) - else None - } - - override def empty = new JConcurrentMapDeprecatedWrapper(new juc.ConcurrentHashMap[A, B]) - - def putIfAbsent(k: A, v: B): Option[B] = { - val r = underlying.putIfAbsent(k, v) - if (r != null) Some(r) else None - } - - def remove(k: A, v: B): Boolean = underlying.remove(k, v) - - def replace(k: A, v: B): Option[B] = { - val prev = underlying.replace(k, v) - if (prev != null) Some(prev) else None - } - - def replace(k: A, oldvalue: B, newvalue: B): Boolean = - underlying.replace(k, oldvalue, newvalue) - } - case class JConcurrentMapWrapper[A, B](val underlying: juc.ConcurrentMap[A, B]) extends mutable.AbstractMap[A, B] with JMapWrapperLike[A, B, JConcurrentMapWrapper[A, B]] with concurrent.Map[A, B] { override def get(k: A) = { val v = underlying get k diff --git a/src/library/scala/collection/mutable/ConcurrentMap.scala b/src/library/scala/collection/mutable/ConcurrentMap.scala deleted file mode 100644 index 5b5d738d03..0000000000 --- a/src/library/scala/collection/mutable/ConcurrentMap.scala +++ /dev/null @@ -1,90 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2010-2013, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.collection -package mutable - -/** A template trait for mutable maps that allow concurrent access. - * - * $concurrentmapinfo - * - * @since 2.8 - * @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#concurrent_maps "Scala's Collection Library overview"]] - * section on `Concurrent Maps` for more information. - * - * @tparam A the key type of the map - * @tparam B the value type of the map - * - * @define Coll `ConcurrentMap` - * @define coll concurrent map - * @define concurrentmapinfo - * This is a base trait for all Scala concurrent map implementations. It - * provides all of the methods a `Map` does, with the difference that all the - * changes are atomic. It also describes methods specific to concurrent maps. - * - * '''Note''': The concurrent maps do not accept `'''null'''` for keys or values. - * - * @define atomicop - * This is an atomic operation. - */ -@deprecated("Use `scala.collection.concurrent.Map` instead.", "2.10.0") -trait ConcurrentMap[A, B] extends Map[A, B] { - - /** - * Associates the given key with a given value, unless the key was already - * associated with some other value. - * - * $atomicop - * - * @param k key with which the specified value is to be associated with - * @param v value to be associated with the specified key - * @return `Some(oldvalue)` if there was a value `oldvalue` previously - * associated with the specified key, or `None` if there was no - * mapping for the specified key - */ - def putIfAbsent(k: A, v: B): Option[B] - - /** - * Removes the entry for the specified key if its currently mapped to the - * specified value. - * - * $atomicop - * - * @param k key for which the entry should be removed - * @param v value expected to be associated with the specified key if - * the removal is to take place - * @return `true` if the removal took place, `false` otherwise - */ - def remove(k: A, v: B): Boolean - - /** - * Replaces the entry for the given key only if it was previously mapped to - * a given value. - * - * $atomicop - * - * @param k key for which the entry should be replaced - * @param oldvalue value expected to be associated with the specified key - * if replacing is to happen - * @param newvalue value to be associated with the specified key - * @return `true` if the entry was replaced, `false` otherwise - */ - def replace(k: A, oldvalue: B, newvalue: B): Boolean - - /** - * Replaces the entry for the given key only if it was previously mapped - * to some value. - * - * $atomicop - * - * @param k key for which the entry should be replaced - * @param v value to be associated with the specified key - * @return `Some(v)` if the given key was previously mapped to some value `v`, or `None` otherwise - */ - def replace(k: A, v: B): Option[B] -} diff --git a/test/files/neg/javaConversions-2.10-ambiguity.check b/test/files/neg/javaConversions-2.10-ambiguity.check deleted file mode 100644 index c064a22964..0000000000 --- a/test/files/neg/javaConversions-2.10-ambiguity.check +++ /dev/null @@ -1,6 +0,0 @@ -javaConversions-2.10-ambiguity.scala:8: error: type mismatch; - found : scala.collection.concurrent.Map[String,String] - required: scala.collection.mutable.ConcurrentMap[String,String] - assertType[mutable.ConcurrentMap[String, String]](a) - ^ -one error found diff --git a/test/files/neg/javaConversions-2.10-ambiguity.scala b/test/files/neg/javaConversions-2.10-ambiguity.scala deleted file mode 100644 index e856846a29..0000000000 --- a/test/files/neg/javaConversions-2.10-ambiguity.scala +++ /dev/null @@ -1,10 +0,0 @@ -import collection.{JavaConversions, mutable, concurrent} -import JavaConversions._ -import java.util.concurrent.{ConcurrentHashMap => CHM} - -object Bar { - def assertType[T](t: T) = t - val a = new CHM[String, String]() += (("", "")) - assertType[mutable.ConcurrentMap[String, String]](a) -} -// vim: set et: diff --git a/test/files/pos/javaConversions-2.10-ambiguity.scala b/test/files/pos/javaConversions-2.10-ambiguity.scala new file mode 100644 index 0000000000..c4aad6cbfc --- /dev/null +++ b/test/files/pos/javaConversions-2.10-ambiguity.scala @@ -0,0 +1,10 @@ +import collection.{JavaConversions, mutable, concurrent} +import JavaConversions._ +import java.util.concurrent.{ConcurrentHashMap => CHM} + +object Bar { + def assertType[T](t: T) = t + val a = new CHM[String, String]() += (("", "")) + assertType[concurrent.Map[String, String]](a) +} +// vim: set et: diff --git a/test/files/pos/javaConversions-2.10-regression.scala b/test/files/pos/javaConversions-2.10-regression.scala index e1b81015ba..7c7ff03b55 100644 --- a/test/files/pos/javaConversions-2.10-regression.scala +++ b/test/files/pos/javaConversions-2.10-regression.scala @@ -3,10 +3,10 @@ import JavaConversions._ import java.util.concurrent.{ConcurrentHashMap => CHM} object Foo { - def buildCache2_9_simple[K <: AnyRef, V <: AnyRef]: mutable.ConcurrentMap[K, V] = - asScalaConcurrentMap(new CHM()) + def buildCache2_9_simple[K <: AnyRef, V <: AnyRef]: concurrent.Map[K, V] = + mapAsScalaConcurrentMap(new CHM()) - def buildCache2_9_implicit[K <: AnyRef, V <: AnyRef]: mutable.ConcurrentMap[K, V] = + def buildCache2_9_implicit[K <: AnyRef, V <: AnyRef]: concurrent.Map[K, V] = new CHM[K, V]() } diff --git a/test/files/run/map_java_conversions.scala b/test/files/run/map_java_conversions.scala index 7714b2cc74..751167c04d 100644 --- a/test/files/run/map_java_conversions.scala +++ b/test/files/run/map_java_conversions.scala @@ -19,7 +19,7 @@ object Test { val concMap = new java.util.concurrent.ConcurrentHashMap[String, String] test(concMap) - val cmap = asScalaConcurrentMap(concMap) + val cmap = mapAsScalaConcurrentMap(concMap) cmap.putIfAbsent("absentKey", "absentValue") cmap.put("somekey", "somevalue") assert(cmap.remove("somekey", "somevalue") == true) -- cgit v1.2.3