Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eduardoschmidtsantos/f1f5242a8f627872b5f029e1aca44d03 to your computer and use it in GitHub Desktop.
Save eduardoschmidtsantos/f1f5242a8f627872b5f029e1aca44d03 to your computer and use it in GitHub Desktop.
temp
public List<Area> findByParent(Long id){
return areaRepository.findByParentId(id);
}
public List<Area> findChildrensById(Long id){
Area current = findById(id);
ArrayList<Area> areas = new ArrayList<>();
buildChildrensById(areas, current);
areas.sort(Comparator.comparing(Area::getId));
return areas;
}
private void buildChildrensById(List<Area> areas, Area currentParent){
areas.add(currentParent);
List<Area> childrens = findByParent(currentParent.getId());
for (Area children : childrens) {
buildChildrensById(areas, children);
}
if(currentParent.getInherited() != null && !areas.contains(currentParent.getInherited())){
buildChildrensById(areas, currentParent.getInherited());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment