1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 package net.objectlab.qalab.parser;
40
41 import net.objectlab.qalab.util.QALabTags;
42
43 import java.util.Date;
44
45 /**
46 * A class to store each result which are stored as part of the FileStat. This
47 * class holds the following data; date, no. of errors and the type of reporting
48 *
49 * @author Paramjit Rehinsi
50 * @version $Revision: 242 $
51 */
52 public class SingleStat {
53 private static final int FULL_COVERAGE = 100;
54
55 /** If the type is a Cobertura type, change the value to be 100 - value. **/
56 private static final String COBERTURA_BRANCH = "cobertura-branch";
57
58 /** If the type is a Cobertura type, change the value to be 100 - value. **/
59 private static final String COBERTURA_LINE = "cobertura-line";
60
61 /**
62 * Date and time of the statistics.
63 */
64 private Date datetime = null;
65
66 /**
67 * stat value detected.
68 */
69 private int statvalue = -1;
70
71 /**
72 * type of error detected.
73 */
74 private String type;
75
76 /**
77 * @param date
78 * the date and time of detection of the errors.
79 */
80 public final void setDate(final Date date) {
81 this.datetime = new Date(date.getTime());
82 }
83
84 /**
85 * @return the date and time of detection of the errors.
86 */
87 public final Date getDate() {
88 if (datetime != null) {
89 return new Date(datetime.getTime());
90 } else {
91 return null;
92 }
93 }
94
95 /**
96 * @param errors
97 * the error count detected.
98 */
99 public final void setStatValue(final int errors) {
100 this.statvalue = errors;
101 if (type != null) {
102 checkForInversion();
103 }
104 }
105
106 private void checkForInversion() {
107 if (statvalue != -1 && (COBERTURA_BRANCH.equals(type) || COBERTURA_LINE.equals(type))) {
108 statvalue = FULL_COVERAGE - statvalue;
109 }
110 }
111
112 /**
113 * @return the error count.
114 */
115 public final int getStatValue() {
116 return this.statvalue;
117 }
118
119 /**
120 * @param statisticsType
121 * checkstyle|findbugs|pmd|simian
122 */
123 public final void setType(final String statisticsType) {
124 this.type = statisticsType;
125 checkForInversion();
126 }
127
128 /**
129 * @return the statistic type
130 */
131 public final String getType() {
132 return this.type;
133 }
134
135 /**
136 * @return a text representation
137 */
138 public final String toString() {
139 StringBuffer buf = new StringBuffer();
140
141 buf.append(type).append(" - ");
142 buf.append(QALabTags.DEFAULT_DATETIME_FORMAT.format(datetime));
143 buf.append(" - V:").append(statvalue);
144
145 return buf.toString();
146 }
147 }
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163