Last active
August 29, 2015 14:12
-
-
Save devth/e21aaccefe2b7c277ded to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getOrCreate[A](m: JMap[Any, Any], key: Any, create: A): A = { | |
if (m.containsKey(key)) m.get(key).asInstanceOf[A] | |
else { | |
m.put(key, create) | |
create | |
} | |
} | |
def storeAtPath(m: JMap[Any, Any], path: Seq[String], values: Seq[Any]) { | |
path.toList match { | |
case key :: Nil => { | |
// Insert the value | |
m.put(key, values) | |
} | |
case key :: rest => { | |
// Create another submap | |
val subMap = getOrCreate(m, key, new JHashMap[Any, Any]) | |
storeAtPath(subMap, rest, values) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment