Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1572e96

Browse files
committed
Refine MapOps in concurrent.Map, add MapFactory
The `buildFromMapOps` implicit has `CC[X, Y] <: Map[X, Y] with MapOps[X, Y, CC, _]` For `CC = concurrent.Map` the bound is not satisfied, we had `MapOps[_, _, mutable.Map, _]`.
1 parent ec97e82 commit 1572e96

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/library/scala/collection/concurrent/Map.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
*/
1212

1313
package scala
14-
package collection.concurrent
14+
package collection
15+
package concurrent
1516

1617
import scala.annotation.tailrec
18+
import scala.collection.mutable
1719

1820
/** A template trait for mutable maps that allow concurrent access.
1921
*
@@ -35,7 +37,11 @@ import scala.annotation.tailrec
3537
* @define atomicop
3638
* This is an atomic operation.
3739
*/
38-
trait Map[K, V] extends scala.collection.mutable.Map[K, V] {
40+
trait Map[K, V] extends mutable.Map[K, V]
41+
with mutable.MapOps[K, V, Map, Map[K, V]]
42+
with MapFactoryDefaults[K, V, Map, mutable.Iterable] {
43+
44+
override def mapFactory: MapFactory[Map] = Map
3945

4046
/**
4147
* Associates the given key with a given value, unless the key was already
@@ -188,3 +194,5 @@ trait Map[K, V] extends scala.collection.mutable.Map[K, V] {
188194
this
189195
}
190196
}
197+
198+
object Map extends MapFactory.Delegate[Map](TrieMap)

src/library/scala/collection/convert/JavaCollectionWrappers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ private[collection] object JavaCollectionWrappers extends Serializable {
474474
@SerialVersionUID(3L)
475475
class JConcurrentMapWrapper[K, V](val underlying: juc.ConcurrentMap[K, V])
476476
extends AbstractJMapWrapper[K, V]
477+
with JMapWrapperLike[K, V, concurrent.Map, concurrent.Map[K, V]]
477478
with concurrent.Map[K, V] {
478479

479480
override def get(k: K) = Option(underlying get k)

test/junit/scala/collection/BuildFromTest.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class BuildFromTest {
187187
implicitly[BuildFrom[immutable.LongMap[_], (Long, String), immutable.LongMap[String]]]
188188
implicitly[BuildFrom[mutable.AnyRefMap[_ <: AnyRef, _], (String, String), mutable.AnyRefMap[String, String]]]
189189
implicitly[BuildFrom[mutable.AnyRefMap[String, String], (String, String), _]]
190+
implicitly[BuildFrom[mutable.Map[String, String], (String, String), mutable.Map[String, String]]]
191+
implicitly[BuildFrom[concurrent.Map[String, String], (String, String), concurrent.Map[String, String]]]
190192

191193
// Check that collection companions can implicitly be converted to a `BuildFrom` instance
192194
Iterable: BuildFrom[_, Int, Iterable[Int]]

0 commit comments

Comments
 (0)