-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathEachLineStations.java
More file actions
56 lines (44 loc) · 1.53 KB
/
Copy pathEachLineStations.java
File metadata and controls
56 lines (44 loc) · 1.53 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
package subway.line;
import subway.common.Prefix;
import subway.station.Station;
import java.util.ArrayList;
import java.util.List;
public class EachLineStations {
private static final String STATION_NUMBER_LACK = Prefix.ERROR.getPrefix() + "등록된 역이 2개 이하이므로 삭제할 수 없습니다.";
private static final int MIN_ORDER_NUMBER = 1;
private static final int MIN_STATION_NUMBER = 2;
private static final int SET_POSITION_INDEX = 1;
private List<Station> stations;
public EachLineStations() {
this.stations = new ArrayList<>();
}
public EachLineStations(List<Station> stations) {
this.stations = stations;
}
public List<Station> getStations() {
return stations;
}
public void addStation(Station station) {
stations.add(station);
}
public boolean isRegistered(String name) {
for (Station station : stations) {
if (station.isSame(name)) {
return true;
}
}
return false;
}
public void addSection(Station station, int sectionNumber) {
stations.add(sectionNumber - SET_POSITION_INDEX, station);
}
public boolean isNotExistSection(int number) {
return number < MIN_ORDER_NUMBER || number > stations.size() + SET_POSITION_INDEX;
}
public void deleteStation(Station station) {
if (stations.size() <= MIN_STATION_NUMBER) {
throw new IllegalArgumentException(STATION_NUMBER_LACK);
}
stations.remove(station);
}
}