-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathStationRepository.java
More file actions
39 lines (32 loc) · 1.08 KB
/
Copy pathStationRepository.java
File metadata and controls
39 lines (32 loc) · 1.08 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
package subway.domain;
import java.util.*;
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 boolean contains(String name) {
for(int i=0; i<stations().size(); i++) {
final Station station = stations().get(i);
if(station.getName().equals(name)) {
return true;
}
}
return false;
}
public static Optional<Station> findByName(String name) {
for(int i=0; i<stations().size(); i++) {
final Station station = stations().get(i);
if(station.getName().equals(name)) {
return Optional.of(station);
}
}
return Optional.empty();
}
}