我有一种方法需要根据2 Map[Integer, Data]
创建Sets
。它是参数的一种合并,其中map中的键是集合中每个元组的键,值是Data
使用元组值构造的对象。
def craete(included: Set[(Int, Set[Int])], excluded: Set[(Int, Set[Int])]) {
//create new Map[Integer, Data]...
}
和dataObject类:
class Data(included: Seq[Integer], excluded: Seq[Integer]) {
}
答案 0 :(得分:2)
case class Data(included: Set[Int], excluded: Set[Int])
def create(included: Map[Int, Set[Int]], excluded: Map[Int, Set[Int]]): Map[Int, Data] = {
val keys = included.keySet union excluded.keySet
keys.iterator.map(id => id -> Data(
included.getOrElse(id, Set.empty),
excluded.getOrElse(id, Set.empty))
).toMap
}
请注意,scala中没有Integer