I answered one of your related questions yesterday, so let's continue with the code I posted :)
public class FamilyNode {
public FamilyNode findNodeByName(String nodeName){
if(name.equals(nodeName)){
return this;
}
for(FamilyNode child : children){
if(child.findNodeByName(nodeName) != null)
return child;
}
return null;
}
public void addChild(FamilyNode child){
children.add(child);
}
}
Basically, you need to find the node you are looking for (by name in this case), and this can be done using the findNodeByNameabove. Once the node is found, add one child to it.
Use this code as follows:
FamilyNode root = ...;
FamilyNode node = root.findNodeByName("Parent");
if(node != null) node.addChild(...);
, :
public FamilyNode findNodeByName(String nodeName){
System.out.println("Visiting node "+ name);
for(FamilyNode child : children){
child.findNodeByName(nodeName)
}
return null;
}