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