-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathStationRepository.java
More file actions
40 lines (32 loc) · 1.17 KB
/
Copy pathStationRepository.java
File metadata and controls
40 lines (32 loc) · 1.17 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
package subway.domain;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class StationRepository {
private static final List<Station> stations = new ArrayList<>();
static {
stations.add(new Station("교대역"));
stations.add(new Station("강남역"));
stations.add(new Station("역삼역"));
stations.add(new Station("남부터미널역"));
stations.add(new Station("양재역"));
stations.add(new Station("양재시민의숲역"));
stations.add(new Station("매봉역"));
}
public static List<Station> stations() {
return Collections.unmodifiableList(stations);
}
public static void addStation(Station station) {
stations.add(station);
}
public static boolean deleteStation(String name) {
return stations.removeIf(station -> Objects.equals(station.getName(), name));
}
public static void deleteAll() {
stations.clear();
}
public static Station findStation(String name) {
return stations.stream().filter(station -> Objects.equals(station.getName(), name)).findFirst().get();
}
}