1 package uk.ac.cam.spectra;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7
8
9
10
11
12
13 public final class Validation implements Serializable {
14
15
16
17
18 private static final long serialVersionUID = 5073928556668966397L;
19
20 private final List<String> errors = new ArrayList<String>();
21
22 private final List<String> warnings = new ArrayList<String>();
23
24 public boolean hasErrors() {
25 return !errors.isEmpty();
26 }
27
28 public boolean hasWarnings() {
29 return !warnings.isEmpty();
30 }
31
32 public List<String> getErrors() {
33 return errors;
34 }
35
36 public List<String> getWarnings() {
37 return warnings;
38 }
39
40 public String toString() {
41 StringBuilder sb = new StringBuilder(250);
42 sb.append("Validation: ");
43 if (hasErrors()) {
44 sb.append("Failed!");
45 } else if (hasWarnings()) {
46 sb.append("Warning!");
47 } else {
48 sb.append("OK.");
49 }
50 if(hasErrors()||hasWarnings()) {
51 sb.append("\n").append("Errors: \n");
52 for(String s : errors) {
53 sb.append(" - ").append(s).append("\n");
54 }
55 sb.append("Warnings: \n");
56 for(String s : warnings) {
57 sb.append(" - ").append(s);
58 }
59 }
60 return sb.toString();
61 }
62 }