1 package org.apache.maven.plugins.checkstyle;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Objects;
23 import java.util.StringJoiner;
24
25
26
27
28 class Violation
29 {
30
31
32
33
34 protected static final String NO_COLUMN = "-1";
35
36
37 private final String source;
38
39
40 private final String file;
41
42 private final String line;
43
44 private String column = NO_COLUMN;
45
46 private final String severity;
47
48 private final String message;
49
50 private final String ruleName;
51
52 private final String category;
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 Violation( String source,
75 String file,
76 String line,
77 String severity,
78 String message,
79 String ruleName,
80 String category )
81 {
82 this.source = Objects.requireNonNull( source );
83 this.file = file;
84 this.line = line;
85 this.severity = Objects.requireNonNull( severity );
86 this.message = Objects.requireNonNull( message );
87 this.ruleName = Objects.requireNonNull( ruleName );
88 this.category = Objects.requireNonNull( category );
89 }
90
91
92
93
94
95
96 protected String getSource( )
97 {
98 return source;
99 }
100
101
102
103
104
105
106 protected String getFile( )
107 {
108 return file;
109 }
110
111
112
113
114
115
116 protected String getLine( )
117 {
118 return line;
119 }
120
121
122
123
124
125
126 protected String getColumn( )
127 {
128 return column;
129 }
130
131
132
133
134
135 protected void setColumn( String column )
136 {
137 if ( column == null || column.length() < 1 )
138 {
139 this.column = NO_COLUMN;
140 }
141 else
142 {
143 this.column = column;
144 }
145 }
146
147
148
149
150
151
152 protected String getSeverity( )
153 {
154 return severity;
155 }
156
157
158
159
160
161
162 protected String getMessage( )
163 {
164 return message;
165 }
166
167
168
169
170
171
172 protected String getRuleName( )
173 {
174 return ruleName;
175 }
176
177
178
179
180
181
182 protected String getCategory( )
183 {
184 return category;
185 }
186
187 @Override
188 public boolean equals( Object other )
189 {
190 if ( this == other )
191 {
192 return true;
193 }
194 if ( !( other instanceof Violation ) )
195 {
196 return false;
197 }
198 Violation violation = ( Violation ) other;
199 return line.equals( violation.line )
200 && Objects.equals( column, violation.column )
201 && source.equals( violation.source )
202 && file.equals( violation.file )
203 && severity.equals( violation.severity )
204 && message.equals( violation.message )
205 && ruleName.equals( violation.ruleName )
206 && category.equals( violation.category );
207 }
208
209 @Override
210 public int hashCode()
211 {
212 return Objects.hash( source, file, line, column, severity, message, ruleName, category );
213 }
214
215 @Override
216 public String toString()
217 {
218 return new StringJoiner( ", ", Violation.class.getSimpleName() + "[", "]" )
219 .add( "source='" + source + "'" )
220 .add( "file='" + file + "'" )
221 .add( "line=" + line )
222 .add( "column=" + column )
223 .add( "severity='" + severity + "'" )
224 .add( "message='" + message + "'" )
225 .add( "ruleName='" + ruleName + "'" )
226 .add( "category='" + category + "'" )
227 .toString();
228 }
229 }