I'm new to Groovy, but I am trying to write a simple recursive method to parse hierarchical paths into an object graph. Here is what I've tried:
class Hierarchy {
def root = [:]
static void processHierarchy(names, parent) {
println names
if (names.size() > 0) {
def childName = names[0]
def child = parent[childName]
if (child == null){
child = new Expando()
parent[childName]= child
}
processHierarchy(names[1..-1], child)
}
}
Hierarchy () {
def names = '/some/thing/to/test'.split('/')
if (names != null && names.size() > 0){
processHierarcy(names, this.root)
}
println this.root
}
}
new Hierarchy()
But I get the following error:
Caught: groovy.lang.MissingMethodException: No signature of method: Hierarchy.processHierarcy() is applicable for argument types: ([Ljava.lang.String;, java.util.LinkedHashMap) values: [[, some, thing, to, test], [:]]
Possible solutions: processHierarchy(java.lang.Object, java.lang.Object)
groovy.lang.MissingMethodException: No signature of method: Hierarchy.processHierarcy() is applicable for argument types: ([Ljava.lang.String;, java.util.LinkedHashMap) values: [[, some, thing, to, test], [:]]
Possible solutions: processHierarchy(java.lang.Object, java.lang.Object)
at Hierarchy.<init>(xxx.groovy:48)
at xxx.run(xxx.groovy:54)
What am I missing here?