-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathStationRepository.java
More file actions
36 lines (29 loc) · 1.01 KB
/
Copy pathStationRepository.java
File metadata and controls
36 lines (29 loc) · 1.01 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
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 boolean deleteStation(String name) {
return stations.removeIf(station -> Objects.equals(station.getName(), name));
}
public static void deleteAll() {
stations.clear();
}
public static void findStationByName(String stationName) {
Station station = stations.stream()
.filter(s -> s.getName().equals(stationName))
.findAny()
.orElse(null);
if (station.equals(null)) {
throw new IllegalArgumentException("\n[ERROR] 해당 역은 존재하지 않습니다.");
}
}
}