I have a problem with a recursive method that fills a structure LinkedHashMap<String,LinkedHashMap<String, Integer>>. I don’t know if the call of function in the last return is in the right place – i have tried putting it in three different places now:
public static LinkedHashMap<String, LinkedHashMap<String, Integer>> GetXMLRegularExpression(
Node node, LinkedHashMap<String, LinkedHashMap<String, Integer>> a) {
List<Element> children = getChildren(node);
List<String> childrenString = ConversionString(children);
List<String> Clear = RemoveDuplicate(children);
LinkedHashMap<String, Integer> lhm = new LinkedHashMap<String, Integer>();
// System.out.println(childrenString);
if (!isLeaf(node)) {
for (int i = 0; i < Clear.size(); i++) {
int count = NumberOfAppear(childrenString, Clear.get(i));
lhm.put(Clear.get(i), count);
}
a.put(node.getNodeName(), lhm);
return a;
} else {
lhm.put(node.getNodeName(), 0);
a.put(node.getNodeName(), lhm);
return a;
}
for (int j = 0; j < children.size(); j++) {
return GetXMLRegularExpression(children.get(j), a);
}
}
The code looks problematic. You embedded the “return” statement in a loop, which is strange. Are you trying to return multiple value from this function? On the 1st iteration of the loop, the “return” statement will be executed which ends execution of this function.