1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 /***
23 * Used to contain and run a number of Diagnostic instances.
24 * @author jamie
25 */
26 public class Diagnostics implements DiagnosticContainer {
27
28 private List diagnostics = new ArrayList();
29 private List diagnosticContainers = new ArrayList();
30 private String name = Diagnostics.class.getName();
31
32 /***
33 * Create an empty Diagnostics. Diagnostics will
34 * have to be set using setDiagnostics()
35 * @see #setDiagnostics(List)
36 */
37 public Diagnostics() {
38
39 }
40
41 /***
42 * Create a Diagnostics with a list of children
43 * @param diagnostics diagnostics that will get
44 * run with diagnose() is called on this class.
45 */
46 public Diagnostics(List diagnosticContainers, List diagnostics) {
47 this.diagnostics = diagnostics;
48 this.diagnosticContainers = diagnosticContainers;
49 }
50
51 /***
52 * Sets the name of this diagnostic
53 * @param name the new Fully Qualified Name
54 */
55 public void setName(String name) {
56 this.name = name;
57 }
58
59 /***
60 * @return the name of this Diagnostic, defaults to the
61 * FQN class name.
62 */
63 public String getName() {
64 return name;
65 }
66
67 /***
68 * Set the diagnostics that will be run
69 * @param diagnostics
70 */
71 public void setDiagnostics(List diagnostics) {
72 this.diagnostics = Collections.unmodifiableList(diagnostics);
73 }
74
75 public void setDiagnosticContainers(List diagnosticContainers) {
76 this.diagnosticContainers = Collections.unmodifiableList(diagnosticContainers);
77 }
78
79 /***
80 * Add a diagnostic to the diagnostics contained in this
81 * class. Once this diagnostic has been set into a DiagnosticRunner
82 * this method should not be called.
83 *
84 * @param diagnostic another diagnostic that should be run
85 * when diagnose() is run.
86 */
87 public void addDiagnostic(Diagnostic diagnostic) {
88 if(this.diagnostics == null) {
89 this.diagnostics = new ArrayList();
90 }
91 this.diagnostics.add(diagnostic);
92 }
93
94 /***
95 * @return a list of child diagnostics
96 */
97 public List getDiagnostics() {
98 return diagnostics;
99 }
100
101 /***
102 * @see org.jdiagnose.DiagnosticContainer#getDiagnosticContainers()
103 */
104 public List getDiagnosticContainers() {
105 return diagnosticContainers;
106 }
107
108 /***
109 * @param diagnostic
110 */
111 public void addDiagnosticContainer(DiagnosticContainer container) {
112 diagnosticContainers.add(container);
113 }
114 }