-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathLine.java
More file actions
61 lines (52 loc) · 1.61 KB
/
Copy pathLine.java
File metadata and controls
61 lines (52 loc) · 1.61 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.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Line {
private String name;
private List<Station> stations;
private List<Integer> distance;
private List<Integer> time;
public Line(String name, List<Station> stations, List<Integer> distance, List<Integer> time) {
this.name = name;
this.stations = stations;
this.distance = distance;
this.time = time;
}
public Station nextStation(Station station, int upDown) {
int nextIndex = stations.indexOf(station) + upDown;
if (stations.size() > nextIndex && nextIndex >= 0) {
return stations.get(nextIndex);
}
return null;
}
public int totalDistance(Station station, int upDown) {
if(!LineRepository.isNotTerminal(station)) {
return 0;
}
int index = stations.indexOf(station);
if (0 > upDown) {
return distance.get(index-1);
}
return distance.get(index);
}
public int takingTime(Station station, int upDown) {
if(!LineRepository.isNotTerminal(station)) {
return 0;
}
int index = stations.indexOf(station);
if (0 > upDown) {
return time.get(index-1);
}
return time.get(index);
}
public String getName() {
return name;
}
public boolean haveStation(Station station) {
return stations.contains(station);
}
public List<Station> getTerminals() {
return Arrays.asList(stations.get(0), stations.get(stations.size()-1));
}
}