Created
July 5, 2017 19:44
-
-
Save eduardoschmidtsantos/f1f5242a8f627872b5f029e1aca44d03 to your computer and use it in GitHub Desktop.
temp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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