From e068345288f9a7fe8f4d3eb23fe0b91240132de1 Mon Sep 17 00:00:00 2001 From: Aleksandar Prokopec Date: Thu, 12 Feb 2015 20:10:31 +0100 Subject: Fix SI-9147 Override `getOrElseUpdate` in `concurrent.Map`. Also, add a ScalaCheck test. --- src/library/scala/collection/concurrent/Map.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') 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 + } + } + } -- cgit v1.2.3