-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemError.java
More file actions
103 lines (89 loc) · 3.46 KB
/
SystemError.java
File metadata and controls
103 lines (89 loc) · 3.46 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
/**
* Created by PsichO on 06.10.2014.
*/
public class SystemError implements Comparable<SystemError> {
int errorId;
String errorTitle;
String errorDescription;
/**
* Конструктор.
* @param errorId -- Код ошибки.
* @param errorTitle -- Имя ошибки.
* @param errorDescription -- Описание ошибки.
*/
public SystemError(int errorId, String errorTitle, String errorDescription) {
this.errorId = errorId;
this.errorTitle = errorTitle;
this.errorDescription = errorDescription;
}
public SystemError(){
}
/**
* Функция для задания одинакового хэшкода для входного объекта.
* Она необходима для удаления нужного элемента.
* @return возвращает хэшкод для объекта.
*/
public int hashCode(){
int hashcode = 0;
hashcode = errorId * 10;
hashcode += errorTitle.hashCode();
hashcode += errorDescription.hashCode();
return hashcode;
}
/**
* Эквивалентность и хеш-код тесно связанны между собой,
* поскольку хеш-код вычисляется на основании содержимого объекта (значения полей)
* и если у двух объектов одного и того же класса содержимое одинаковое,
* то и хеш-коды должны быть одинаковые.
* @param obj Входной объект.
* @return возвращает true если сравниваемые объекты одинаковы и false в противоположном случае.
*/
public boolean equals(Object obj){
if(obj instanceof SystemError){
SystemError error = (SystemError) obj;
return (error.errorTitle.equals(this.errorTitle) && error.errorDescription.equals(this.errorDescription) && error.errorId == this.errorId);
} else {
return false;
}
}
/**
*
* @return возвращает информацию в заданном формате.
*/
@Override
public String toString() {
return "ErrorObject: " +
"errorId = " + errorId +
", errorTitle = '" + errorTitle + '\'' +
", errorDescription = '" + errorDescription + '\'' +
';';
}
/**
* Функция, необходимая для сортировки.
* @param o входной объект.
* @return method must return negative number if current object is less than other object,
* positive number if current object is greater than other object and zero if both objects are equal to each other.
*/
@Override
public int compareTo(SystemError o) {
return toString().compareTo(o.toString());
}
public int getErrorId() {
return errorId;
}
public void setErrorId(int errorId) {
this.errorId = errorId;
}
public String getErrorTitle() {
return errorTitle;
}
public void setErrorTitle(String errorTitle) {
this.errorTitle = errorTitle;
}
public String getErrorDescription() {
return errorDescription;
}
public void setErrorDescription(String errorDescription) {
this.errorDescription = errorDescription;
}
}