Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
0d8bafce
Commit
0d8bafce
authored
Mar 08, 2017
by
Peter van 't Hof
Browse files
Fixed a small bug
parent
17328f96
Changes
2
Hide whitespace changes
Inline
Side-by-side
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/ConfigUtils.scala
View file @
0d8bafce
...
...
@@ -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 */
...
...
biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/ConfigUtilsTest.scala
View file @
0d8bafce
...
...
@@ -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
=
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment