Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. public class ParentService {
  2.  
  3. public getParentList(String parentSetLookup) {
  4. List<Parent> parentList = getParentList(parentSetLookup);
  5. List<Integer> parentIdList = getParentIds(parentList);
  6. List<ChildOne> childOneList = getChildOneList(parentIdList);
  7. List<ChildTwo> childTwoList = getChildTwoList(parentIdList);
  8. List<ChildThree> childthreeList = getChildThreeList(parentIdList);
  9.  
  10. mapChildrenToParent(parentList, childOneList);
  11. mapChildrenToParent(parentList, childTwoList);
  12. mapChildrenToParent(parentList, childThreeList);
  13.  
  14. return parentList;
  15. }
  16.  
  17. private void mapChildrenToParent(List<Parent> parentList, List<ChildBaseClass> childList) {
  18. for (Parent parent : parentList) {
  19. for (ChildBaseClass child : childList) {
  20. if (child.getParentId().equals(parent.getParentId())) {
  21. %%%parent.getChildList().add(child);%%%
  22. }
  23. }
  24. }
  25. }
  26.  
  27. public class GrandParent {
  28. List<Parent> parent = new ArrayList<>();
  29.  
  30. // Getter and Setter
  31. }
  32.  
  33. public class Parent {
  34. private Integer parentId;
  35. private List<ChildOne> childOneList = new ArrayList<>();
  36. private List<ChildTwo> childTwoList = new ArrayList<>();
  37. private List<ChildThree> childThreeList = new ArrayList<>();
  38.  
  39. // Getters and Setters
  40. }
  41.  
  42. public abstract class ChildBaseClass {
  43. private Integer parentId;
  44.  
  45. // Getter Setter
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement