-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathLineRepository.java
More file actions
39 lines (32 loc) · 1 KB
/
Copy pathLineRepository.java
File metadata and controls
39 lines (32 loc) · 1 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 LineRepository {
private static final List<Line> lines = new ArrayList<>();
public static List<Line> lines() {
return Collections.unmodifiableList(lines);
}
public static void addLine(Line line) {
lines.add(line);
}
public static boolean deleteLineByName(String name) {
return lines.removeIf(line -> Objects.equals(line.getName(), name));
}
public static boolean contains(String name) {
for(int i=0; i<lines().size(); i++) {
final Line line = lines().get(i);
if(line.getName().equals(name)) {
return true;
}
}
return false;
}
public static Optional<Line> findByName(String name) {
for(int i=0; i<lines().size(); i++) {
final Line line = lines().get(i);
if(line.getName().equals(name)) {
return Optional.of(line);
}
}
return Optional.empty();
}
}