-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathLine.java
More file actions
61 lines (46 loc) · 1.54 KB
/
Copy pathLine.java
File metadata and controls
61 lines (46 loc) · 1.54 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
package subway.domain;
import java.util.LinkedList;
import static resource.TextResource.*;
public class Line {
private String name;
private StationsInLine stations;
private Paths paths;
public Line(String name, Station startStation, Station endStation, Path path) {
this.name = name;
checkValid(startStation.getName(), endStation.getName());
createStationInLine(startStation, endStation);
createPaths(path);
}
private void checkValid(String startStation, String endStation) {
if (startStation.equals(endStation)) {
throw new IllegalArgumentException(ERROR_START_END_STATION_DUPLICATED);
}
}
private void createStationInLine(Station startStation, Station endStation) {
LinkedList<Station> stations = new LinkedList<>();
stations.addFirst(startStation);
stations.addLast(endStation);
this.stations = new StationsInLine(stations);
}
private void createPaths(Path path) {
LinkedList<Path> paths = new LinkedList<>();
paths.addFirst(path);
this.paths = new Paths(paths);
}
public String getName() {
return name;
}
public void addStation(Station station, int order) {
stations.addStation(station, order);
}
public void addPath(Path path, int order) {
int limit = stations.getSize();
paths.addPath(path, order, limit);
}
public StationsInLine getStations() {
return stations;
}
public Paths getPaths() {
return paths;
}
}