1 package org.codehaus.mojo.dashboard.report.plugin.beans;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.ArrayList;
20 import java.util.Date;
21 import java.util.Iterator;
22 import java.util.List;
23
24
25
26
27
28
29
30
31
32
33 public class CheckstyleReportBean extends AbstractReportBean
34 {
35
36
37
38 private int nbClasses;
39
40
41
42
43 private int nbInfos;
44
45
46
47
48 private int nbWarnings;
49
50
51
52
53 private int nbErrors;
54
55
56
57
58 private int nbTotal;
59
60
61
62
63 private List errors;
64
65
66
67
68
69 public CheckstyleReportBean()
70 {
71 this.errors = new ArrayList();
72 }
73
74
75
76
77
78 public CheckstyleReportBean( Date dateGeneration )
79 {
80 super( dateGeneration );
81 this.errors = new ArrayList();
82 }
83
84
85
86
87
88 public int getNbClasses()
89 {
90 return nbClasses;
91 }
92
93
94
95
96
97 public void setNbClasses( int nbClasses )
98 {
99 this.nbClasses = nbClasses;
100 }
101
102
103
104
105
106 public int getNbErrors()
107 {
108 return nbErrors;
109 }
110
111
112
113
114
115 public void setNbErrors( int nbErrors )
116 {
117 this.nbErrors = nbErrors;
118 }
119
120
121
122
123
124 public int getNbInfos()
125 {
126 return nbInfos;
127 }
128
129
130
131
132
133 public void setNbInfos( int nbInfos )
134 {
135 this.nbInfos = nbInfos;
136 }
137
138
139
140
141
142 public int getNbTotal()
143 {
144 return nbTotal;
145 }
146
147
148
149
150
151 public void setNbTotal( int nbTotal )
152 {
153 this.nbTotal = nbTotal;
154 }
155
156
157
158
159
160 public int getNbWarnings()
161 {
162 return nbWarnings;
163 }
164
165
166
167
168
169 public void setNbWarnings( int nbWarnings )
170 {
171 this.nbWarnings = nbWarnings;
172 }
173
174
175
176
177
178
179
180 public List getErrors()
181 {
182 return this.errors;
183 }
184
185
186
187
188
189
190
191
192 public void setErrors( List errorsList )
193 {
194 this.errors = errorsList;
195 }
196
197
198
199
200
201 public void addError( CheckstyleError error )
202 {
203 if ( this.errors.isEmpty() )
204 {
205 this.errors.add( error );
206 }
207 else
208 {
209 if ( ( this.errors.contains( error ) ) )
210 {
211
212 int index = this.errors.indexOf( error );
213
214 int nbIter = ( (CheckstyleError) this.errors.get( index ) ).getNbIteration();
215 ( (CheckstyleError) this.errors.get( index ) ).setNbIteration( nbIter + error.getNbIteration() );
216 }
217 else
218 {
219 this.errors.add( error );
220 }
221 }
222 }
223
224
225
226
227
228
229 public void addAllError( List errorsList )
230 {
231 if ( this.errors.isEmpty() )
232 {
233 Iterator iter = errorsList.iterator();
234 while ( iter.hasNext() )
235 {
236 CheckstyleError error = (CheckstyleError) iter.next();
237 this.errors.add( (CheckstyleError) ( error.clone() ) );
238 }
239 }
240 else
241 {
242 Iterator iter = errorsList.iterator();
243 while ( iter.hasNext() )
244 {
245 CheckstyleError error = (CheckstyleError) iter.next();
246 this.addError( (CheckstyleError) ( error.clone() ) );
247 }
248 }
249 }
250
251
252
253
254
255
256 public void merge( IDashBoardReportBean dashboardReport )
257 {
258 if ( dashboardReport != null && dashboardReport instanceof CheckstyleReportBean )
259 {
260 this.nbClasses = this.nbClasses + ( (CheckstyleReportBean) dashboardReport ).getNbClasses();
261
262 this.nbInfos = this.nbInfos + ( (CheckstyleReportBean) dashboardReport ).getNbInfos();
263
264 this.nbWarnings = this.nbWarnings + ( (CheckstyleReportBean) dashboardReport ).getNbWarnings();
265
266 this.nbErrors = this.nbErrors + ( (CheckstyleReportBean) dashboardReport ).getNbErrors();
267
268 this.nbTotal = this.nbTotal + ( (CheckstyleReportBean) dashboardReport ).getNbTotal();
269
270
271 this.addAllError( ( (CheckstyleReportBean) dashboardReport ).getErrors() );
272 }
273 }
274
275
276
277
278 protected Object clone()
279 {
280 CheckstyleReportBean clone = new CheckstyleReportBean( this.getDateGeneration() );
281 clone.setNbClasses( this.nbClasses );
282 clone.setNbInfos( this.nbInfos );
283 clone.setNbWarnings( this.nbWarnings );
284 clone.setNbErrors( this.nbErrors );
285 clone.setNbTotal( this.nbTotal );
286 clone.addAllError( this.getErrors() );
287 return clone;
288 }
289
290 public double getPercentInfos()
291 {
292 return getPercentageValue( this.nbInfos, this.nbTotal );
293 }
294
295 public double getPercentErrors()
296 {
297 return getPercentageValue( this.nbErrors, this.nbTotal );
298 }
299
300 public double getPercentWarnings()
301 {
302 return getPercentageValue( this.nbWarnings, this.nbTotal );
303 }
304
305 }