-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathErrors.java
More file actions
101 lines (88 loc) · 3.48 KB
/
Copy pathErrors.java
File metadata and controls
101 lines (88 loc) · 3.48 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
package subway.domain;
import java.util.List;
public class Errors {
public static boolean checkInput(String input, List<String> functions) {
boolean check = true;
if (!functions.contains(input)) {
ErrorMessage.displayErrorMessage(Constants.FUNCTION_INPUT_ERROR);
check = false;
}
return check;
}
public static void checkSameStation(String name) {
if (StationRepository.isExist(name)) {
ErrorMessage.displayErrorMessage(Constants.ALREADY_EXIST_ERROR);
throw new IllegalArgumentException();
}
}
public static void checkSameLine(String name) {
if (LineRepository.isExist(name)) {
ErrorMessage.displayErrorMessage(Constants.ALREADY_EXIST_ERROR);
throw new IllegalArgumentException();
}
}
public static void checkSameName(String firstName, String lastName) {
if (firstName.equals(lastName)) {
ErrorMessage.displayErrorMessage(Constants.SAME_NAME_ERROR);
throw new IllegalArgumentException();
}
}
public static void checkTextLength(String name) {
if (name.length() < 2) {
ErrorMessage.displayErrorMessage(Constants.NAME_LENGTH_ERROR);
throw new IllegalArgumentException();
}
}
public static void checkExistStation(String name) {
if (!StationRepository.isExist(name)) {
ErrorMessage.displayErrorMessage(Constants.NO_SUCH_NAME_ERROR);
throw new IllegalArgumentException();
}
}
public static void checkExistLine(String name) {
if (!LineRepository.isExist(name)) {
ErrorMessage.displayErrorMessage(Constants.NO_SUCH_NAME_ERROR);
throw new IllegalArgumentException();
}
}
public static void checkInLine(String name) {
for (Line line : LineRepository.lines())
if (line.hasStation(name)) {
ErrorMessage.displayErrorMessage(Constants.HAS_IN_LINE_ERROR);
throw new IllegalArgumentException();
}
}
public static Line checkInSpecificLine(String lineName, String stationName) {
Line line = LineRepository.getLineByName(lineName);
if (line.hasStation(stationName)) {
ErrorMessage.displayErrorMessage(Constants.HAS_IN_SPECIFIC_LINE_ERROR);
throw new IllegalArgumentException();
}
return line;
}
public static void checkNotInSpecificLine(String lineName, String stationName) {
Line line = LineRepository.getLineByName(lineName);
if (!line.hasStation(stationName)) {
ErrorMessage.displayErrorMessage(Constants.HAS_NOT_IN_SPECIFIC_LINE_ERROR);
throw new IllegalArgumentException();
}
}
public static void checkValidIndex(Line line, String index) {
try {
int intIndex = Integer.parseInt(index);
int size = line.getSize();
if (intIndex < 1 || intIndex > size+1)
throw new IndexOutOfBoundsException();
} catch (Exception e) {
ErrorMessage.displayErrorMessage(Constants.UNVALID_INDEX_ERROR);
throw new IllegalArgumentException();
}
}
public static void checkValidLine(String name) {
Line line = LineRepository.getLineByName(name);
if (line.getSize() < 3) {
ErrorMessage.displayErrorMessage(Constants.CANT_DELETE_SECTION_ERROR);
throw new IllegalArgumentException();
}
}
}