在scala中读取配置文件时出现问题

xzlaal3s  于 2021-05-19  发布在  Spark
关注(0)|答案(0)|浏览(328)
intersect = {
1 = {
  hits = {
      min = 2
    }
  dwellTime = {
    min = 10
    max = 20
  }
}
3 = {
  hits = {
    min = 2
  }
  dwellTime = {
    min = 10
    max = 20
  }
}
5 = {
  hits = {
    min = 2
  }
  dwellTime = {
    min = 10
    max = 20
  }
}
}

我试着这样读:

private def toMap(hashMap: AnyRef): Map[String, AnyRef] = hashMap.asInstanceOf[java.util.Map[String, AnyRef]].asScala.toMap

lazy val someConfig: Map[Int, Map[String, Map[String, Int]]] =
config.getList("intersect").unwrapped().asScala.map({
  someConfigItem => toMap(someConfigItem).map({
    case (k1, v1) => k1.toInt -> toMap(v1).map({
        x => toMap(x).map{
          case (k2, v2) => k2 -> toMap(v2).map({
            y => toMap(y) map{
              case (k2, v2) => k2 -> v2.toString.toInt
            }
          })
        }
      })
  })
}).reduceLeft(_ ++ _)

它将引发以下错误:
错误:(100,18)类型不匹配;
found:scala.collection.immutable.map[int,scala.collection.immutable.iterable[scala.collection.immutable.map[string,scala.collection.immutable.iterable[scala.collection.immutable.map[string,int]]]]]]
必选:map[int,map[string,map[string,int]]}).reduceleft(u216;+++)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题