-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathStationService.java
More file actions
51 lines (44 loc) · 1.4 KB
/
Copy pathStationService.java
File metadata and controls
51 lines (44 loc) · 1.4 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
package subway;
import subway.domain.Station;
import subway.domain.StationRepository;
public class StationService {
public static final int MIN_STATION_NAME_LENGTH = 2;
public static boolean isNotStationState(String name) {
if (name.length() < MIN_STATION_NAME_LENGTH) {
OutPut.printStationNameLengthError();
return true;
}
if (StationRepository.isEqualStationName(name)) {
OutPut.printStationNameDuplicateError();
return true;
}
return false;
}
public static boolean addStation(String name, boolean isPrint) {
if (isNotStationState(name)) {
return false;
}
StationRepository.addStation(new Station(name));
if (isPrint) {
OutPut.printStationCreateMessage();
}
return true;
}
public static boolean deleteStation(String name) {
if (StationRepository.isExistByLineInStation(name)) {
OutPut.printStationDeleteError();
return false;
}
if (!StationRepository.deleteStation(name)) {
OutPut.printNonExistStationError(name);
return false;
}
OutPut.printStationDeleteMessage();
return true;
}
public static void print() {
for (Station station : StationRepository.stations()) {
OutPut.printName(station.getName());
}
}
}