-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathSubway.java
More file actions
70 lines (60 loc) · 1.71 KB
/
Copy pathSubway.java
File metadata and controls
70 lines (60 loc) · 1.71 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
58
59
60
61
62
63
64
65
66
67
68
69
70
package subway.controller;
/*
* Subway
*
* version 1.0
*
* 2020.12.15
*
* Copyright (c) by Davinci.J
*/
import subway.Constants;
import subway.domain.LineRepository;
import subway.domain.StationRepository;
import subway.manager.LineManager;
import subway.manager.SectionManager;
import subway.manager.StationManager;
import subway.view.InputView;
import subway.view.OutputView;
import java.util.Arrays;
public class Subway {
static {
StationRepository.init();
LineRepository.init();
}
private enum Menu {
STATION("1", StationManager::selectMenu),
LINE("2", LineManager::selectMenu),
SECTION("3", SectionManager::selectMenu),
SUBWAY_LIST("4", OutputView::printLineAndStation),
QUIT("Q", new Subway()::exit);
private final String name;
private final Runnable runnable;
Menu(String name, Runnable runnable) {
this.name = name;
this.runnable = runnable;
}
public static void execute(String input) {
Arrays.stream(values())
.filter(value -> value.name.equals(input))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(Constants.WRONG_STATE_TRY_AGAIN))
.runnable.run();
}
}
public static void run() {
try {
String state = InputView.inputMainMenu();
Menu.execute(state);
if (!state.equals(Constants.APPLICATION_QUIT)) {
run();
}
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
run();
}
}
private void exit() {
System.exit(0);
}
}