Skip to content

Commit

Permalink
Merge pull request #1438 from xuwei-k/delete-MultiMap
Browse files Browse the repository at this point in the history
[2.x] avoid deprecated collection.mutable.MultiMap
  • Loading branch information
eed3si9n authored Oct 6, 2024
2 parents 43a74cf + 9a6a3a7 commit 040309b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/zinc-testing/src/main/scala/xsbti/TestCallback.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,18 @@ object TestCallback {
}

private def pairsToMultiMap[A, B](pairs: Seq[(A, B)]): Map[A, Set[B]] = {
import scala.collection.mutable.{ HashMap, MultiMap }
val emptyMultiMap = new HashMap[A, scala.collection.mutable.Set[B]] with MultiMap[A, B]
val multiMap = pairs.foldLeft(emptyMultiMap) {
case (acc, (key, value)) =>
acc.addBinding(key, value)
import scala.collection.mutable.HashMap
val multiMap = HashMap.empty[A, scala.collection.mutable.Set[B]]
pairs.foreach {
case (key, value) =>
multiMap.get(key) match {
case None =>
val set = collection.mutable.Set.empty[B]
set += value
multiMap(key) = set
case Some(set) =>
set += value
}
}
// convert all collections to immutable variants
multiMap.toMap.view.mapValues(_.toSet).toMap.withDefaultValue(Set.empty)
Expand Down

0 comments on commit 040309b

Please sign in to comment.