本文整理汇总了Scala中java.util.LinkedHashMap类的典型用法代码示例。如果您正苦于以下问题:Scala LinkedHashMap类的具体用法?Scala LinkedHashMap怎么用?Scala LinkedHashMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LinkedHashMap类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: DocumentMerger
//设置package包名称以及导入依赖的类
package eu.tznvy.jancy.modulesgen.helpers
import java.util.{ArrayList, LinkedHashMap}
import scala.collection.JavaConverters._
object DocumentMerger {
def merge(
document: LinkedHashMap[String, Object],
fragment: LinkedHashMap[String, Object]
): LinkedHashMap[String, Object] = {
val result = new LinkedHashMap[String, Object](document)
for(key <- fragment.keySet().asScala) {
val bothHaveKey = result.keySet().contains(key)
val areMaps = (bothHaveKey
&& result.get(key).isInstanceOf[LinkedHashMap[_, _]]
&& fragment.get(key).isInstanceOf[LinkedHashMap[_, _]])
val areLists = (!areMaps && bothHaveKey
&& result.get(key).isInstanceOf[ArrayList[_]]
&& fragment.get(key).isInstanceOf[ArrayList[_]])
if (areMaps) {
val curMap = result.get(key).asInstanceOf[LinkedHashMap[String, Object]]
val fragmentMap = fragment.get(key).asInstanceOf[LinkedHashMap[String, Object]]
val merged = merge(curMap, fragmentMap)
result.put(key, merged)
} else if (areLists) {
val curList = result.get(key).asInstanceOf[ArrayList[Object]]
val curListCopy = new ArrayList[Object](curList)
val fragmentList = fragment.get(key).asInstanceOf[ArrayList[Object]]
curListCopy.addAll(fragmentList)
result.put(key, curListCopy)
} else {
result.put(key, fragment.get(key))
}
}
result
}
}