-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathSQLQueryError.java
More file actions
116 lines (97 loc) · 2.66 KB
/
SQLQueryError.java
File metadata and controls
116 lines (97 loc) · 2.66 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package sqlancer.common.query;
import java.util.Objects;
public class SQLQueryError implements Comparable<SQLQueryError> {
public enum ErrorLevel {
WARNING, ERROR
}
private ErrorLevel level;
private int code;
private String message;
public void setLevel(ErrorLevel level) {
this.level = level;
}
public void setCode(int code) {
this.code = code;
}
public void setMessage(String message) {
this.message = message;
}
public ErrorLevel getLevel() {
return level;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
public boolean hasSameLevel(SQLQueryError that) {
if (level == null) {
return that.getLevel() == null;
} else {
return level.equals(that.getLevel());
}
}
public boolean hasSameCodeAndMessage(SQLQueryError that) {
if (code != that.getCode()) {
return false;
}
if (message == null) {
return that.getMessage() == null;
} else {
return message.equals(that.getMessage());
}
}
@Override
public boolean equals(Object that) {
if (that == null) {
return false;
}
if (that instanceof SQLQueryError) {
SQLQueryError thatError = (SQLQueryError) that;
return hasSameLevel(thatError) && hasSameCodeAndMessage(thatError);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(level, code, message);
}
@Override
public String toString() {
return String.format("Level: %s; Code: %d; Message: %s.", level, code, message);
}
@Override
public int compareTo(SQLQueryError that) {
if (code < that.getCode()) {
return -1;
} else if (code > that.getCode()) {
return 1;
}
if (level == null && that.getLevel() != null) {
return -1;
} else {
if (that.getLevel() == null) {
return 1;
} else {
int res = level.compareTo(that.getLevel());
if (res != 0) {
return res;
}
}
}
if (message == null && that.getMessage() != null) {
return -1;
} else {
if (that.getMessage() == null) {
return 1;
} else {
int res = message.compareTo(that.getMessage());
if (res != 0) {
return res;
}
}
}
return 0;
}
}