Scala:mutable.Map [A​​ny,mutable.Map [A​​ny,IndexedSeq [Any]]问题

时间:2019-03-20 14:23:13

标签: scala mutable

尝试在第二张可变地图中放置物品时,我遇到了一个小问题。 我的目标是:收集位于许多不同xml文件中的某些元素,并按照它们所属的层次结构进行组织(这些文件是非结构化的混乱,类别似乎没有逻辑顺序地给出)。 这些元素是:类别的层次结构级别(1-x,1是顶层),其级别为iLevel,类别代码为catCode,其名称,以及(如果需要)其父项的名称(所有名称均位于namesCategories中)

val categoryMap = mutable.Map.empty[Int, mutable.Map[String, IndexedSeq[String]]]

...
//Before: search in a first file links to other files
// for each category file found, will treat it and store it for further treatement.
matches.foreach{f =>
        ....
       //Will search for a specific regex, and for each matches store what we are interested in
      matchesCat.foreach{t =>
        sCat = t.replaceFirst((system_env + """\S{4}"""), "")
        //iLevel given by the number of '/' remaining in the string
        iLevel = sCat.count(_ == '/')
        //reset catCode and namesCategories
        catCode = ""
        namesCategories.clear()
   //Search and extract the datas from sCat using premade regex patterns
        sCat match {
          case patternCatCode(codeCat) => catCode = s"$codeCat"
        }
        //remove the category code to prepare to extract names
        sCat.replace(patternCatCode.toString(), "")
        //extract names
        do {
          sCat match {
            case patternCatNames(name) => namesCategories += s"$name"
          }
          sCat.replace(patternCatNames.toString(), "")
        }while(sCat!="")

        // create the level entry if it doesn't exist
        if(!(categoryMap.contains(iLevel))) {
            categoryMap.put(iLevel, mutable.Map.empty[String, IndexedSeq[String]])
        }

        //Try to add my cat code and the names, which must be in order for further treatment, to my map
        categoryMap(iLevel).put(catCode, namesCategories.clone())


      }
    }
  }

问题: 类型不匹配,预期:IndexedSeq [String],实际:mutable.Builder [String,IndexedSeq [String]]

正如特拉维斯·布朗(Travis Brown)亲切指出的那样,我遇到类型不匹配的问题,但是我不知道如何解决该问题并使总体思路起作用。

我试图将代码仅保留在此处相关的内容,如果需要更多内容,我将再次进行编辑。

有什么提示吗?

感谢您的帮助

0 个答案:

没有答案