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

Skip to content

Refine MapOps in concurrent.Map, add MapFactory #10891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.13.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/library/scala/collection/concurrent/Map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
*/

package scala
package collection.concurrent
package collection
package concurrent

import scala.annotation.tailrec
import scala.collection.mutable

/** A template trait for mutable maps that allow concurrent access.
*
Expand All @@ -35,7 +37,11 @@ import scala.annotation.tailrec
* @define atomicop
* This is an atomic operation.
*/
trait Map[K, V] extends scala.collection.mutable.Map[K, V] {
trait Map[K, V] extends mutable.Map[K, V]
with mutable.MapOps[K, V, Map, Map[K, V]]
with MapFactoryDefaults[K, V, Map, mutable.Iterable] {

override def mapFactory: MapFactory[Map] = Map

/**
* Associates the given key with a given value, unless the key was already
Expand Down Expand Up @@ -188,3 +194,5 @@ trait Map[K, V] extends scala.collection.mutable.Map[K, V] {
this
}
}

object Map extends MapFactory.Delegate[Map](TrieMap)
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ private[collection] object JavaCollectionWrappers extends Serializable {
@SerialVersionUID(3L)
class JConcurrentMapWrapper[K, V](val underlying: juc.ConcurrentMap[K, V])
extends AbstractJMapWrapper[K, V]
with JMapWrapperLike[K, V, concurrent.Map, concurrent.Map[K, V]]
with concurrent.Map[K, V] {

override def get(k: K) = Option(underlying get k)
Expand Down
2 changes: 2 additions & 0 deletions test/junit/scala/collection/BuildFromTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class BuildFromTest {
implicitly[BuildFrom[immutable.LongMap[_], (Long, String), immutable.LongMap[String]]]
implicitly[BuildFrom[mutable.AnyRefMap[_ <: AnyRef, _], (String, String), mutable.AnyRefMap[String, String]]]
implicitly[BuildFrom[mutable.AnyRefMap[String, String], (String, String), _]]
implicitly[BuildFrom[mutable.Map[String, String], (String, String), mutable.Map[String, String]]]
implicitly[BuildFrom[concurrent.Map[String, String], (String, String), concurrent.Map[String, String]]]

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