-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathLineRepository.java
More file actions
40 lines (32 loc) · 1.17 KB
/
Copy pathLineRepository.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.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
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 void deleteAll() {
lines.clear();
}
public static List<Line> findLinesContainStation(Station station) {
return lines.stream().filter(line -> line.haveStation(station)).collect(Collectors.toList());
}
//TODO 하나만 찾는 라인
public static Line findLineContainStation(Station station) {
return lines.stream().filter(line -> line.haveStation(station)).findAny().get();
}
public static boolean isNotTerminal(Station station) {
return lines.stream().noneMatch(line -> line.getTerminals().contains(station));
}
}