Commit 0d8bafce authored by Peter van 't Hof's avatar Peter van 't Hof

Fixed a small bug

parent 17328f96
......@@ -102,13 +102,15 @@ object ConfigUtils extends Logging {
* @return Some(value) or None if not found
*/
def getValueFromPath(map: Map[String, Any], path: List[String]): Option[Any] = {
val value = map.get(path.head)
if (path.tail.isEmpty || value.isEmpty) value
else value.get match {
case map: Map[_, _] => getValueFromPath(map.asInstanceOf[Map[String, Any]], path.tail)
case map: java.util.LinkedHashMap[_, _] => getValueFromPath(map.toMap.asInstanceOf[Map[String, Any]], path.tail)
case _ => None
}
if (path.nonEmpty) {
val value = map.get(path.head)
if (path.tail.isEmpty || value.isEmpty) value
else value.get match {
case map: Map[_, _] => getValueFromPath(map.asInstanceOf[Map[String, Any]], path.tail)
case map: java.util.LinkedHashMap[_, _] => getValueFromPath(map.toMap.asInstanceOf[Map[String, Any]], path.tail)
case _ => None
}
} else Some(map)
}
/** Make json aboject from a file */
......
......@@ -38,6 +38,7 @@ class ConfigUtilsTest extends TestNGSuite with Matchers {
getValueFromPath(map1, List("nested3", "nested2", "nested1")) shouldBe Some(Map("dummy" -> 1))
getValueFromPath(map1, List("notexist", "dummy")) shouldBe None
getValueFromPath(map1, List("dummy", "notexist")) shouldBe None
getValueFromPath(map1, List()) shouldBe Some(map1)
}
@Test def testGetMapFromPath(): Unit = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment