-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathLineRepository.java
More file actions
57 lines (48 loc) · 1.67 KB
/
Copy pathLineRepository.java
File metadata and controls
57 lines (48 loc) · 1.67 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package subway.domain;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class LineRepository {
private static final String INFO = "[INFO] ";
private static final String INFO_WITH_BORDER = "[INFO] ---";
private static final String LINE_LIST = "## 노선 목록";
private static final String SUBWAY_MAP = "## 지하철 노선도";
private static final String LINE_NOT_EXIST = "[ERROR] 존재하지 않는 노선입니다.";
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 isLineExist(String lineName) {
boolean flag = false;
for (Line line : lines) {
flag = line.getName().equals(lineName);
if(flag) break;
}
if (!flag) {
throw new IllegalArgumentException(LINE_NOT_EXIST);
}
}
public static void printLines() {
System.out.println(LINE_LIST);
for (Line line : lines) {
System.out.println(INFO + line.getName());
}
System.out.println();
}
public static void printMap() {
System.out.println();
System.out.println(SUBWAY_MAP);
for (Line line : lines) {
System.out.println(INFO + line.getName());
System.out.println(INFO_WITH_BORDER);
line.printStations();
}
}
}