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.regex.Pattern;
20
21
22
23
24
25
26
27 public class CheckstyleError implements Cloneable
28 {
29
30 private static final Pattern REGEXP_QUOTE = Pattern.compile( "'.*?'" );
31
32
33 private static final Pattern REGEXP_IS_NUMBER = Pattern.compile( "is (\\d)+" );
34
35
36 private static final Pattern REGEXP_NUMBER_TIMES = Pattern.compile( "(\\d)+ times" );
37
38
39 private static final Pattern REGEXP_DOUBELQUOTE = Pattern.compile( "\".*?\"" );
40
41
42 private static final Pattern REGEXP_BRAKET = Pattern.compile( "\\[.*?\\]" );
43
44
45
46
47 private String nameClass;
48
49
50
51
52 private int nbIteration;
53
54
55
56
57 private String type;
58
59
60
61
62 private String message;
63
64
65
66
67 public CheckstyleError()
68 {
69 this.nbIteration = 1;
70 }
71
72
73
74
75
76
77
78 public CheckstyleError( String type, String nameClass, String message, int nbIteration )
79 {
80 this.type = type;
81 this.nameClass = nameClass;
82 this.message = message;
83 this.nbIteration = nbIteration;
84 }
85
86
87
88
89 public CheckstyleError( CheckstyleError object )
90 {
91 this.type = object.getType();
92 this.nameClass = object.getNameClass();
93 this.message = object.getMessage();
94 this.nbIteration = object.getNbIteration();
95 }
96
97 public String getNameClass()
98 {
99 return this.nameClass;
100 }
101
102 public int getNbIteration()
103 {
104 return this.nbIteration;
105 }
106
107 public String getType()
108 {
109 return this.type;
110 }
111
112 public String getMessage()
113 {
114 return this.message;
115 }
116
117 public void setNameClass( String nameClass )
118 {
119 this.nameClass = nameClass;
120 }
121
122 public void setNbIteration( int nbIteration )
123 {
124 this.nbIteration = nbIteration;
125 }
126
127 public void setType( String type )
128 {
129 this.type = type;
130 }
131
132 public void setMessage( String message )
133 {
134 this.message = this.messageTreatment( message );
135 }
136
137 public boolean equals( Object o )
138 {
139 if ( !( o instanceof CheckstyleError ) )
140 {
141 return false;
142 }
143 else
144 {
145 CheckstyleError checkError = new CheckstyleError( (CheckstyleError) o );
146 return ( this.message == null && checkError.getMessage() == null )
147 || ( this.message != null && this.message.equals( checkError.getMessage() ) );
148 }
149 }
150
151
152
153
154
155
156
157
158
159
160
161
162
163 public void increment()
164 {
165 this.nbIteration++;
166 }
167
168 public String toString()
169 {
170 return "[" + this.type + " ; " + this.nameClass + " ; " + this.message + " ; " + this.nbIteration + "]";
171 }
172
173 private String messageTreatment( String message )
174 {
175 String finalMessage = REGEXP_QUOTE.matcher( message ).replaceAll( "'X'" );
176
177 finalMessage = REGEXP_IS_NUMBER.matcher( finalMessage ).replaceFirst( "is 'n'" );
178
179 finalMessage = REGEXP_NUMBER_TIMES.matcher( finalMessage ).replaceFirst( "'n' times" );
180
181 finalMessage = REGEXP_DOUBELQUOTE.matcher( finalMessage ).replaceAll( "\"X\"" );
182
183 finalMessage = REGEXP_BRAKET.matcher( finalMessage ).replaceAll( "[...]" );
184
185 return finalMessage;
186 }
187
188
189
190
191 protected Object clone()
192 {
193 Object clone = null;
194 try
195 {
196 clone = super.clone();
197 }
198 catch ( CloneNotSupportedException e )
199 {
200 System.err.println( "CheckstyleError can't clone" );
201 }
202 return clone;
203 }
204 }