Consider the following code:
CLASS AuditProgressReport :
public class AuditProgressReport { private List<AuditProgressReport> audit_progress_reports = null; private String name = null; private String description = null; private int compliant; private int non_compliant; private int not_completed ; public AuditProgressReport() { super(); } public AuditProgressReport( String name_param, int compliant_param, int non_compliant_param, int not_completed_param) { super(); this.name = name_param; this.compliant = compliant_param; this.non_compliant = non_compliant_param; this.not_completed = not_completed_param; } public void addToCompliant(int compl_to_add_param) { this.compliant += compl_to_add_param; } public void addToNonCompliant(int non_compl_to_add_param) { this.non_compliant += non_compl_to_add_param; } public void addToNotCompleted(int not_compl_param) { this.not_completed += not_compl_param; } public void setAuditProgressReports(List<AuditProgressReport> report_category_nodes_param) { this.audit_progress_reports = report_category_nodes_param; } public List<AuditProgressReport> getAuditProgressReports() { return this.audit_progress_reports; } public void setCompliant(int compliantParam) { this.compliant = compliantParam; } public int getCompliant() { return this.compliant; } public void setNonCompliant(int nonCompliantParam) { this.non_compliant = nonCompliantParam; } public int getNonCompliant() { return this.non_compliant; } public void setNotCompleted(int notCompletedParam) { this.not_completed = notCompletedParam; } public int getNotCompleted() { return this.not_completed; } public void setName(String name_param) { this.name = name_param; } public String getName() { return this.name; } public void setDescription(String description_param) { this.description = description_param; } public String getDescription() { return this.description; } @Override public String toString() { return ("Compliant["+this.compliant+ "] Non-Compliant["+this.non_compliant+ "] Not-Completed["+this.not_completed+"]"); } }
And CLASS Tester :
public class Tester { public static void main(String[] args) { List<AuditProgressReport> main_level = new ArrayList<AuditProgressReport>(); AuditProgressReport ar_1_1 = new AuditProgressReport("ar_1_1",0,0,0); AuditProgressReport ar_1_2 = new AuditProgressReport("ar_1_2",0,0,0); AuditProgressReport ar_1_1_1 = new AuditProgressReport("ar_1_1_1",0,0,0); AuditProgressReport ar_1_1_2 = new AuditProgressReport("ar_1_1_2",15,65,20); AuditProgressReport ar_1_1_3 = new AuditProgressReport("ar_1_1_3",20,30,50); AuditProgressReport ar_1_1_1_1 = new AuditProgressReport("ar_1_1_1_1",5,5,90); AuditProgressReport ar_1_1_1_2 = new AuditProgressReport("ar_1_1_1_2",55,5,40); AuditProgressReport ar_1_1_1_3 = new AuditProgressReport("ar_1_1_1_3",35,35,30); List<AuditProgressReport> arl_1_1_1 = new ArrayList<AuditProgressReport>(); arl_1_1_1.add(ar_1_1_1_1); arl_1_1_1.add(ar_1_1_1_2); arl_1_1_1.add(ar_1_1_1_3); ar_1_1_1.setAuditProgressReports(arl_1_1_1); List<AuditProgressReport> arl_1_1 = new ArrayList<AuditProgressReport>(); arl_1_1.add(ar_1_1_1); arl_1_1.add(ar_1_1_2); arl_1_1.add(ar_1_1_3); AuditProgressReport ar_1_2_1 = new AuditProgressReport("ar_1_2_1",10,30,60); AuditProgressReport ar_1_2_2 = new AuditProgressReport("ar_1_2_2",20,20,60); List<AuditProgressReport> arl_1_2 = new ArrayList<AuditProgressReport>(); arl_1_2.add(ar_1_2_1); arl_1_2.add(ar_1_2_2); ar_1_1.setAuditProgressReports(arl_1_1); ar_1_2.setAuditProgressReports(arl_1_2); main_level.add(ar_1_1); main_level.add(ar_1_2); Tester tester = new Tester(); for(AuditProgressReport prog_rep : main_level) { tester.populateParents(prog_rep, null); }
When you run this, you will notice that the values ββof the parent elements in the list are updated with the sum of the values ββin the child list.
The problem I am facing is that I want it to be updated completely through the tree, and not just the parent itself.
Is there a template that will help me achieve this?
See the illustration below: