for (Tree<String> tree : trees) {
if (null != tree.getChildren()){
chids(tree.getChildren());
pids(tree);
}
}
public void chids(List<Tree<String>> children){
for (Tree<String> child : children) {
HashSet<String> childrenIds = new HashSet<>();
if (null != child.getChildren()){
getChildrenIds(child.getChildren(),childrenIds);
child.put("childrenIds",childrenIds);
chids(child.getChildren());
}
}
}
public void getChildrenIds(List<Tree<String>> children, HashSet<String> chids){
for (Tree<String> child : children) {
chids.add(child.getId());
if (child.getChildren() != null){
getChildrenIds(child.getChildren(),chids);
}
}
}
public void pids(Tree<String> tree){
HashSet<String> pids = new HashSet<>();
pids.add(tree.getParentId());
tree.put("parentsIds",pids);
if (tree.getChildren() != null){
for (Tree<String> child : tree.getChildren()) {
HashSet a = new HashSet();
a.addAll(pids);
a.add(child.getParentId());
child.put("parentsIds",a);
if (null != child.getChildren()){
getParentIds(child.getChildren(),a);
}
}
}
}
public void getParentIds(List<Tree<String>> children, HashSet<String> pids){
for (Tree<String> child : children) {
HashSet a = new HashSet();
a.addAll(pids);
a.add(child.getParentId());
child.put("parentsIds",a);
if (child.getChildren() != null){
getParentIds(child.getChildren(),a);
}
}
}