Refactor project validation, add test
[jSite.git] / src / main / java / de / todesbaum / jsite / application / validation / Issue.java
1 package de.todesbaum.jsite.application.validation;
2
3 import static java.lang.String.format;
4
5 import java.util.Arrays;
6 import java.util.Objects;
7
8 /**
9  * Container class for a single issue. An issue contains an error key that describes the error,
10  * and a fatality flag that determines whether the insert has to be aborted (if the flag is
11  * {@code true}) or if it can still be performed and only a warning should be generated (if the
12  * flag is {@code false}).
13  *
14  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
15  */
16 public class Issue {
17
18         private final String errorKey;
19         private final boolean fatal;
20         private final String[] parameters;
21
22         Issue(String errorKey, boolean fatal, String... parameters) {
23                 this.errorKey = errorKey;
24                 this.fatal = fatal;
25                 this.parameters = parameters;
26         }
27
28         public String getErrorKey() {
29                 return errorKey;
30         }
31
32         public boolean isFatal() {
33                 return fatal;
34         }
35
36         public String[] getParameters() {
37                 return parameters;
38         }
39
40         @Override
41         public boolean equals(Object o) {
42                 if (this == o) {
43                         return true;
44                 }
45                 if (o == null || getClass() != o.getClass()) {
46                         return false;
47                 }
48                 Issue issue = (Issue) o;
49                 return fatal == issue.fatal &&
50                                 Objects.equals(errorKey, issue.errorKey) &&
51                                 Arrays.equals(parameters, issue.parameters);
52         }
53
54         @Override
55         public int hashCode() {
56                 return Objects.hash(errorKey, fatal, parameters);
57         }
58
59         @Override
60         public String toString() {
61                 return format("Issue{errorKey=\"%s\", fatal=%s, parameters=%s}", errorKey, fatal, Arrays.toString(parameters));
62         }
63
64 }