-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathLineService.java
More file actions
65 lines (57 loc) · 2.06 KB
/
Copy pathLineService.java
File metadata and controls
65 lines (57 loc) · 2.06 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
package subway;
import subway.domain.Line;
import subway.domain.LineRepository;
import subway.domain.Station;
import subway.domain.StationRepository;
public class LineService {
public static final int MIN_LINE_NAME_LENGTH = 2;
private static boolean isNotLineNameState(String lineName) {
if (lineName.length() < MIN_LINE_NAME_LENGTH) {
OutPut.printLineLengthError();
return true;
}
if (LineRepository.isEqualLineName(lineName)) {
OutPut.printLineDuplicateError();
return true;
}
return false;
}
private static boolean isNotExistStation(String firstStationName, String lastStationName) {
if (!StationRepository.isEqualStationName(firstStationName)) {
OutPut.printNonExistStationError(firstStationName);
return true;
}
if (!StationRepository.isEqualStationName(lastStationName)) {
OutPut.printNonExistStationError(lastStationName);
return true;
}
return false;
}
public static boolean addLine(String lineName, String firstStationName, String lastStationName,
boolean isPrint) {
if (isNotLineNameState(lineName) || isNotExistStation(firstStationName, lastStationName)) {
return false;
}
Station firstStation = StationRepository.getStation(firstStationName);
Station lastStation = StationRepository.getStation(lastStationName);
Line line = new Line(lineName);
line.initLineInStation(firstStation, lastStation);
LineRepository.addLine(line);
if (isPrint) {
OutPut.printLineCreateMessage();
}
return true;
}
public static void deleteLine(String lineName) {
if (!LineRepository.deleteLineByName(lineName)) {
OutPut.printNonExistLineError();
return;
}
OutPut.printLineDeleteMessage();
}
public static void print() {
for (Line line : LineRepository.lines()) {
OutPut.printName(line.getName());
}
}
}