summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/concurrent/Map.scala
diff options
context:
space:
mode:
authorAleksandar Prokopec <aleksandar.prokopec@gmail.com>2015-02-12 20:10:31 +0100
committerAleksandar Prokopec <aleksandar.prokopec@gmail.com>2015-02-12 20:14:19 +0100
commite068345288f9a7fe8f4d3eb23fe0b91240132de1 (patch)
treea91efcfd624cfb09c3f67e9c56ab3e52d2a25428 /src/library/scala/collection/concurrent/Map.scala
parent178e8df9b6a91375a6162721a0cbc2d90bcc7451 (diff)
downloadscala-e068345288f9a7fe8f4d3eb23fe0b91240132de1.tar.gz
scala-e068345288f9a7fe8f4d3eb23fe0b91240132de1.tar.bz2
scala-e068345288f9a7fe8f4d3eb23fe0b91240132de1.zip
Fix SI-9147 Override `getOrElseUpdate` in `concurrent.Map`.
Also, add a ScalaCheck test.
Diffstat (limited to 'src/library/scala/collection/concurrent/Map.scala')
-rw-r--r--src/library/scala/collection/concurrent/Map.scala11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/library/scala/collection/concurrent/Map.scala b/src/library/scala/collection/concurrent/Map.scala
index 2eea15b8dc..f0a5f57225 100644
--- a/src/library/scala/collection/concurrent/Map.scala
+++ b/src/library/scala/collection/concurrent/Map.scala
@@ -86,4 +86,15 @@ trait Map[A, B] extends scala.collection.mutable.Map[A, B] {
* @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]
+
+ override def getOrElseUpdate(key: A, op: =>B): B = get(key) match {
+ case Some(v) => v
+ case None =>
+ val v = op
+ putIfAbsent(key, v) match {
+ case Some(nv) => nv
+ case None => v
+ }
+ }
+
}