-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathSectionService.java
More file actions
84 lines (75 loc) · 2.58 KB
/
Copy pathSectionService.java
File metadata and controls
84 lines (75 loc) · 2.58 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
package subway;
import subway.domain.Line;
import subway.domain.LineRepository;
import subway.domain.Station;
import subway.domain.StationRepository;
public class SectionService {
private static final int DELETE_MIN_SIZE = 2;
private static final String THREE_MINUS = "---";
private static boolean isNotExistLineAndStation(String lineName, String stationName) {
if (!LineRepository.isEqualLineName(lineName)) {
OutPut.printNonExistLineError();
return true;
}
if (!StationRepository.isEqualStationName(stationName)) {
OutPut.printNonExistStationError(stationName);
return true;
}
return false;
}
private static boolean isExistStation(Line line, String stationName) {
if (line.isExistStation(stationName)) {
OutPut.printExistStationError();
return true;
}
return false;
}
public static boolean addSection(String lineName, String stationName, int stationIndex,
boolean isPrint) {
if (isNotExistLineAndStation(lineName, stationName)) {
return false;
}
Line line = LineRepository.getLine(lineName);
if (isExistStation(line, stationName)) {
return false;
}
Station station = StationRepository.getStation(stationName);
line.insertLineInStation(station, stationIndex);
if (isPrint) {
OutPut.printSectionAddMessage();
}
return true;
}
private static boolean isNotDeleteSize(Line line) {
if (line.lineInStationList().size() <= DELETE_MIN_SIZE) {
OutPut.printSectionDeleteSizeError();
return true;
}
return false;
}
public static boolean deleteSection(String lineName, String stationName) {
if (isNotExistLineAndStation(lineName, stationName)) {
return false;
}
Line line = LineRepository.getLine(lineName);
if (isNotDeleteSize(line)) {
return false;
}
if (!line.deleteLineByName(stationName)) {
OutPut.printNonExistStationError(stationName);
return false;
}
OutPut.printSectionDeleteMessage();
return true;
}
public static void print() {
for (Line line : LineRepository.lines()) {
OutPut.printName(line.getName());
OutPut.printName(THREE_MINUS);
for (Station station : line.lineInStationList()) {
OutPut.printName(station.getName());
}
OutPut.printNextLine();
}
}
}