recently, when dealing with the expansion of a tree (root node with many layers of child nodes), using recursive expansion, there is a problem
TmObject is a node object with child nodes, and objList is an array size = 1, but children has many layers. I hope to find the object corresponding to mObject in this tree through sceneName traversal. The code is as follows. When I equals found this object, I found that the program continued recursion. What caused the problem?
private TmObject loanObjectByName (String sceneName, List < TmObject > objList) {
TmObject temp = getObjByName(sceneName, objList);
if (temp != null) {
return temp;
} else {
for (TmObject scene : objList) {
if (scene.getChildObject().size() > 0) {
loanObjectByName(sceneName, scene.getChildObject());
}
}
}
return null;
}
private TmObject getObjByName(String name, List<TmObject> objList) {
TmObject tmObject = null;
for (TmObject tmTestS : objList) {
if (name.equals(tmTestS.getSceneName())) {
tmObject = tmTestS;
break;
}
}
return tmObject;
}