-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathLine.java
More file actions
59 lines (47 loc) · 1.5 KB
/
Copy pathLine.java
File metadata and controls
59 lines (47 loc) · 1.5 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
package subway.domain;
import java.util.ArrayList;
import java.util.List;
public class Line {
private static final String INFO = "[INFO] ";
private static final String STATION_NUMBER_MESSAGE = "[ERROR] 노선의 역 개수가 2개 이하이므로 삭제할 수 없습니다.";
private String name;
private List<Station> stationsOnLine = new ArrayList<>();
public Line(String name) {
this.name = name;
}
public void registerStation(Station station) {
stationsOnLine.add(station);
}
public boolean isStationRegistered(String stationName) {
for (Station station : stationsOnLine) {
if (station.getName().equals(stationName)) {
return true;
}
}
return false;
}
public void printStations() {
for (Station station : stationsOnLine) {
System.out.println(INFO + station.getName());
}
System.out.println();
}
public String getName() {
return name;
}
public boolean isSameName(String lineName) {
return this.name.equals(lineName);
}
public int getSize() {
return stationsOnLine.size();
}
public void insert(Station station, int order) {
stationsOnLine.add(order-1, station);
}
public void remove(String stationName) {
if (stationsOnLine.size() <= 2) {
throw new IllegalArgumentException(STATION_NUMBER_MESSAGE);
}
stationsOnLine.remove(new Station(stationName));
}
}