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.text.NumberFormat;
20 import java.util.Date;
21
22
23
24
25 public class CloverReportBean extends AbstractReportBean
26 {
27 private int conditionals, statements, methods, elements;
28
29 private int coveredConditionals, coveredStatements, coveredMethods, coveredElements;
30
31 private static final NumberFormat FormatPercent = NumberFormat.getPercentInstance();
32 static
33 {
34 FormatPercent.setMaximumFractionDigits( 1 );
35 }
36
37
38
39
40 public CloverReportBean()
41 {
42
43 }
44
45
46
47
48
49 public CloverReportBean( Date dateGeneration )
50 {
51 super( dateGeneration );
52
53 }
54
55
56
57
58 public int getConditionals()
59 {
60 return conditionals;
61 }
62
63
64
65
66 public String getConditionalsLabel()
67 {
68 return getPercentage( coveredConditionals, conditionals ) + " (" + coveredConditionals + " / " + conditionals
69 + ")";
70 }
71
72
73
74
75
76 public void setConditionals( int conditionals )
77 {
78 this.conditionals = conditionals;
79 }
80
81
82
83
84 public int getCoveredConditionals()
85 {
86 return coveredConditionals;
87 }
88
89
90
91
92
93 public void setCoveredConditionals( int coveredConditionals )
94 {
95 this.coveredConditionals = coveredConditionals;
96 }
97
98
99
100
101 public int getCoveredElements()
102 {
103 return coveredElements;
104 }
105
106
107
108
109
110 public void setCoveredElements( int coveredElements )
111 {
112 this.coveredElements = coveredElements;
113 }
114
115
116
117
118 public int getCoveredMethods()
119 {
120 return coveredMethods;
121 }
122
123
124
125
126
127 public void setCoveredMethods( int coveredMethods )
128 {
129 this.coveredMethods = coveredMethods;
130 }
131
132
133
134
135 public int getCoveredStatements()
136 {
137 return coveredStatements;
138 }
139
140
141
142
143
144 public void setCoveredStatements( int coveredStatements )
145 {
146 this.coveredStatements = coveredStatements;
147 }
148
149
150
151
152 public int getElements()
153 {
154 return elements;
155 }
156
157
158
159
160 public String getElementsLabel()
161 {
162 return getPercentage( coveredElements, elements ) + " (" + coveredElements + " / " + elements + ")";
163 }
164
165
166
167
168
169 public void setElements( int elements )
170 {
171 this.elements = elements;
172 }
173
174
175
176
177 public int getMethods()
178 {
179 return methods;
180 }
181
182
183
184
185 public String getMethodsLabel()
186 {
187 return getPercentage( coveredMethods, methods ) + " (" + coveredMethods + " / " + methods + ")";
188 }
189
190
191
192
193
194 public void setMethods( int methods )
195 {
196 this.methods = methods;
197 }
198
199
200
201
202 public int getStatements()
203 {
204 return statements;
205 }
206
207
208
209
210 public String getStatementsLabel()
211 {
212 return getPercentage( coveredStatements, statements ) + " (" + coveredStatements + " / " + statements + ")";
213 }
214
215
216
217
218
219 public void setStatements( int statements )
220 {
221 this.statements = statements;
222 }
223
224
225
226
227 public void merge( IDashBoardReportBean dashboardReport )
228 {
229 if ( dashboardReport != null && dashboardReport instanceof CloverReportBean )
230 {
231 conditionals += ( (CloverReportBean) dashboardReport ).getConditionals();
232
233 statements += ( (CloverReportBean) dashboardReport ).getStatements();
234
235 methods += ( (CloverReportBean) dashboardReport ).getMethods();
236
237 elements += ( (CloverReportBean) dashboardReport ).getElements();
238
239 coveredConditionals += ( (CloverReportBean) dashboardReport ).getCoveredConditionals();
240
241 coveredStatements += ( (CloverReportBean) dashboardReport ).getCoveredStatements();
242
243 coveredMethods += ( (CloverReportBean) dashboardReport ).getCoveredMethods();
244
245 coveredElements += ( (CloverReportBean) dashboardReport ).getCoveredElements();
246 }
247 }
248
249 private String getPercentage( int numerator, int denominator )
250 {
251 String percent = "0%";
252 if ( denominator > 0 )
253 {
254 double percentage = numerator / (double) denominator;
255 percent = FormatPercent.format( percentage );
256 }
257 return percent;
258 }
259
260 public double getPercentCoveredStatements()
261 {
262 return getPercentageValue( this.coveredStatements, this.statements );
263 }
264
265 public double getPercentCoveredConditionals()
266 {
267 return getPercentageValue( this.coveredConditionals, this.conditionals );
268 }
269
270 public double getPercentCoveredElements()
271 {
272 return getPercentageValue( this.coveredElements, this.elements );
273 }
274
275 public double getPercentCoveredMethods()
276 {
277 return getPercentageValue( this.coveredMethods, this.methods );
278 }
279
280 public double getPercentUnCoveredStatements()
281 {
282 int uncovered = this.statements - this.coveredStatements;
283 return getPercentageValue( uncovered, this.statements );
284 }
285
286 public double getPercentUnCoveredConditionals()
287 {
288 int uncovered = this.conditionals - this.coveredConditionals;
289 return getPercentageValue( uncovered, this.conditionals );
290 }
291
292 public double getPercentUnCoveredElements()
293 {
294 int uncovered = this.elements - this.coveredElements;
295 return getPercentageValue( uncovered, this.elements );
296 }
297
298 public double getPercentUnCoveredMethods()
299 {
300 int uncovered = this.methods - this.coveredMethods;
301 return getPercentageValue( uncovered, this.methods );
302 }
303 }