blob: e3858afdfa2a890b1bec09f7de7041a67a5dbe3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package bjc.everge;
import java.util.ArrayList;
import java.util.List;
/**
* Exception thrown when ReplPair parsing fails
* @author bjculkin
*
*/
public class BadReplParse extends RuntimeException {
/**
* Serialization ID.
*/
private static final long serialVersionUID = 4752304282380556849L;
/**
* The errors that were encountered during parsing.
*/
public List<ReplError> errs;
/**
* Create a new exception for ReplPair parsing failing.
*
* @param msg
* The message for the exception.
*/
public BadReplParse(String msg) {
this(msg, new ArrayList<>());
}
/**
* Create a new exception for ReplPair parsing failing.
*
* @param msg
* The message for the exception.
* @param errs
* The list of errors encountered while parsing.
*/
public BadReplParse(String msg, List<ReplError> errs) {
super(msg);
this.errs = errs;
}
@Override
public String toString() {
String errString;
if (errs.size() == 0) errString = "An error";
else errString = "Errors";
return String.format("%s occured parsing replacement pairs: %s\n%s",
errString, getMessage(), errs);
}
/**
* Convert the exception to a printable format.
*
* @return The exception as a printable format.
*/
public String toPrintString() {
StringBuilder errString = new StringBuilder("[ERROR] ");
if (errs.size() == 0) {
errString.append("No specific errors");
} else if (errs.size() == 1) {
errString.append("An error");
} else {
errString.append(errs.size());
errString.append(" errors");
}
errString.append(" occured parsing replacement pairs:");
if (!getMessage().equals("")) {
errString.append(" ");
errString.append(getMessage());
}
if (errs.size() > 0) {
errString.append("\n\t");
for (ReplError err : errs) {
errString.append(err.toPrintString("\t"));
errString.append("\n\t");
}
}
return errString.toString().trim();
}
}
|