-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathStationRepository.java
More file actions
37 lines (29 loc) · 1022 Bytes
/
Copy pathStationRepository.java
File metadata and controls
37 lines (29 loc) · 1022 Bytes
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
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<>();
public static List<Station> stations() {
return Collections.unmodifiableList(stations);
}
public static void addStation(Station station) {
stations.add(station);
}
public static Station findStationByName(String name) {
return stations.stream()
.filter(station -> station.getName().equals(name))
.findFirst()
.get();
}
public static boolean deleteStation(String name) {
return stations.removeIf(station -> Objects.equals(station.getName(), name));
}
public static boolean isStationPresent(String name) {
return stations.stream().anyMatch(station -> station.getName().equals(name));
}
public static void deleteAll() {
stations.clear();
}
}