From 084a2f347bc2dd8bcac520f19f8e61e15df07e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sat, 2 Sep 2023 22:55:20 +0900 Subject: [PATCH 01/70] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..c6be32f39 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,85 @@ +## 기능 목록 + +### 초기 설정 +- [ ] 사전 등록 정보 초기 설정 + +### 메인 화면 +- [ ] 메인 화면 출력 +- [ ] 원하는 기능 입력 + +### 역 관리 +- [ ] 역 관리 화면 출력 +- [ ] 원하는 기능 입력 + +**역 등록** +- [ ] 등록할 역 이름 입력 + - [ ] 중복된 이름의 역이 있을 경우 예외 발생 + - [ ] 역 이름이 2글자 이상이 아닐 경우 예외 발생 +- [ ] 등록 +- [ ] 등록 완료 안내 출력 + +**역 삭제** +- [ ] 삭제할 역 이름 입력 + - [ ] 존재하지 않는 역일 경우 예외 발생 +- [ ] 삭제 + - [ ] 노선에 등록된 역일 경우 노선에서 삭제 + - [ ] 역 삭제 +- [ ] 삭제 완료 안내 출력 + +**역 조회** +- [ ] 등록되어 있는 역 목록 출력 + +### 노선 관리 + +- [ ] 노선 관리 화면 출력 +- [ ] 원하는 기능 선택 + +**노선 등록** + +- [ ] 등록할 노선 이름 입력 + - [ ] 존재하는 노선일 경우 예외 발생 + - [ ] 1글자 이하일 경우 예외 발생 +- [ ] 상행 종점역 이름 입력 +- [ ] 하행 종점역 이름 입력 + - [ ] 존재하지 않는 역일 경우 예외 발생 + - [ ] 상행 종점역과 하행 종점역이 같을 경우 예외 발생 +- [ ] 노선 생성 + +**노선 삭제** + +- [ ] 삭제할 노선 이름 입력 + - [ ] 존재하지 않는 노선일 경우 예외 발생 +- [ ] 노선 삭제 +- [ ] 삭제 완료 안내 출력 + +**노선 조회** +- [ ] 노선 목록 출력 + +### 구간 관리 + +- [ ] 구간 관리 화면 출력 +- [ ] 원하는 기능 선택 + +**구간 등록** + +- [ ] 노선 이름 입력 + - [ ] 존재하지 않을 경우 예외 발생 +- [ ] 역 이름 입력 + - [ ] 존재하지 않을 경우 예외 발생 + - [ ] 이미 구간에 존재하는 역일 경우 예외 발생 +- 순서 입력 + - [ ] 범위를 벗어날 경우 예외 발생 +- [ ] 구간 등록 +- [ ] 등록 완료 안내 출력 + +**구간 삭제** + +- [ ] 삭제할 노선 입력 + - [ ] 존재하지 않는 노선일 경우 예외 발생 +- [ ] 삭제할 구간의 역 입력 + - [ ] 구간에 존재하지 않는 역일 경우 예외 발생 +- [ ] 삭제 완료 안내 출력 + +### 지하철 노선도 출력 + +- [ ] 지하철 노선도 출력 \ No newline at end of file From 873800c9983fd5f2cf2b2f39479da17242ca1b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sat, 2 Sep 2023 22:59:41 +0900 Subject: [PATCH 02/70] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/{domain => line}/Line.java | 2 +- src/main/java/subway/{domain => line}/LineRepository.java | 2 +- src/main/java/subway/{domain => station}/Station.java | 2 +- src/main/java/subway/{domain => station}/StationRepository.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/subway/{domain => line}/Line.java (89%) rename src/main/java/subway/{domain => line}/LineRepository.java (95%) rename src/main/java/subway/{domain => station}/Station.java (89%) rename src/main/java/subway/{domain => station}/StationRepository.java (95%) diff --git a/src/main/java/subway/domain/Line.java b/src/main/java/subway/line/Line.java similarity index 89% rename from src/main/java/subway/domain/Line.java rename to src/main/java/subway/line/Line.java index f4d738d5a..7c78dffb0 100644 --- a/src/main/java/subway/domain/Line.java +++ b/src/main/java/subway/line/Line.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.line; public class Line { private String name; diff --git a/src/main/java/subway/domain/LineRepository.java b/src/main/java/subway/line/LineRepository.java similarity index 95% rename from src/main/java/subway/domain/LineRepository.java rename to src/main/java/subway/line/LineRepository.java index 49132ddb6..9516b39c4 100644 --- a/src/main/java/subway/domain/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.line; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/subway/domain/Station.java b/src/main/java/subway/station/Station.java similarity index 89% rename from src/main/java/subway/domain/Station.java rename to src/main/java/subway/station/Station.java index bdb142590..735a3aa00 100644 --- a/src/main/java/subway/domain/Station.java +++ b/src/main/java/subway/station/Station.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.station; public class Station { private String name; diff --git a/src/main/java/subway/domain/StationRepository.java b/src/main/java/subway/station/StationRepository.java similarity index 95% rename from src/main/java/subway/domain/StationRepository.java rename to src/main/java/subway/station/StationRepository.java index b7245c0f3..fa5d932be 100644 --- a/src/main/java/subway/domain/StationRepository.java +++ b/src/main/java/subway/station/StationRepository.java @@ -1,4 +1,4 @@ -package subway.domain; +package subway.station; import java.util.ArrayList; import java.util.Collections; From 1466112f6e61062f8137dc6ce61b1374c8647561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 00:15:44 +0900 Subject: [PATCH 03/70] =?UTF-8?q?feat(Initialization):=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/Application.java | 3 +- src/main/java/subway/Initialization.java | 60 +++++++++++++++++++ src/main/java/subway/SubwayController.java | 8 +++ src/main/java/subway/line/Line.java | 9 +-- src/main/java/subway/line/StopStations.java | 14 +++++ src/main/java/subway/station/Station.java | 7 ++- .../subway/station/StationRepository.java | 7 +++ 8 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 src/main/java/subway/Initialization.java create mode 100644 src/main/java/subway/SubwayController.java create mode 100644 src/main/java/subway/line/StopStations.java diff --git a/docs/README.md b/docs/README.md index c6be32f39..4a7bd619c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ ## 기능 목록 ### 초기 설정 -- [ ] 사전 등록 정보 초기 설정 +- [x] 사전 등록 정보 초기 설정 ### 메인 화면 - [ ] 메인 화면 출력 diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 0bcf786cc..9a375891f 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -5,6 +5,7 @@ public class Application { public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); - // TODO: 프로그램 구현 + SubwayController controller = new SubwayController(); + controller.start(); } } diff --git a/src/main/java/subway/Initialization.java b/src/main/java/subway/Initialization.java new file mode 100644 index 000000000..d5cd9f348 --- /dev/null +++ b/src/main/java/subway/Initialization.java @@ -0,0 +1,60 @@ +package subway; + +import subway.line.Line; +import subway.line.LineRepository; +import subway.line.StopStations; +import subway.station.Station; +import subway.station.StationRepository; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class Initialization { + + private static final String STATIONS = "교대역, 강남역, 역삼역, 남부터미널역, 양재역, 양재시민의숲역, 매봉역"; + private static final String LINE_TWO = "2호선"; + private static final String LINE_TWO_STATIONS = "교대역, 강남역, 역삼역"; + private static final String LINE_THREE = "3호선"; + private static final String LINE_THREE_STATIONS = "교대역, 남부터미널역, 양재역, 매봉역"; + private static final String LINE_DX = "신분당선"; + private static final String LINE_DX_STATIONS = "강남역, 양재역, 양재시민의숲역"; + + private static final String REGEX = ", "; + + public static void init() { + initStation(); + initLineTwo(); + initLineThree(); + initLineDX(); + } + + private static void initStation() { + Arrays.stream(STATIONS.split(REGEX)) + .forEach(name -> StationRepository.addStation(new Station(name))); + } + + private static void initLineTwo() { + List stopStation = Arrays.stream(LINE_TWO_STATIONS.split(REGEX)) + .map(StationRepository::findByName) + .collect(Collectors.toList()); + Line line = new Line(LINE_TWO, new StopStations(stopStation)); + LineRepository.addLine(line); + } + + private static void initLineThree() { + List stopStation = Arrays.stream(LINE_THREE_STATIONS.split(REGEX)) + .map(StationRepository::findByName) + .collect(Collectors.toList()); + Line line = new Line(LINE_THREE, new StopStations(stopStation)); + LineRepository.addLine(line); + } + + private static void initLineDX() { + List stopStation = Arrays.stream(LINE_DX_STATIONS.split(REGEX)) + .map(StationRepository::findByName) + .collect(Collectors.toList()); + Line line = new Line(LINE_DX, new StopStations(stopStation)); + LineRepository.addLine(line); + } +} diff --git a/src/main/java/subway/SubwayController.java b/src/main/java/subway/SubwayController.java new file mode 100644 index 000000000..21c2ebd17 --- /dev/null +++ b/src/main/java/subway/SubwayController.java @@ -0,0 +1,8 @@ +package subway; + +public class SubwayController { + + public void start() { + Initialization.init(); + } +} diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index 7c78dffb0..59f0b162e 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -1,15 +1,16 @@ package subway.line; public class Line { - private String name; - public Line(String name) { + private final String name; + private final StopStations stopStations; + + public Line(String name, StopStations stopStations) { this.name = name; + this.stopStations = stopStations; } public String getName() { return name; } - - // 추가 기능 구현 } diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java new file mode 100644 index 000000000..edbc35108 --- /dev/null +++ b/src/main/java/subway/line/StopStations.java @@ -0,0 +1,14 @@ +package subway.line; + +import subway.station.Station; + +import java.util.List; + +public class StopStations { + + private final List element; + + public StopStations(List stations) { + this.element = stations; + } +} diff --git a/src/main/java/subway/station/Station.java b/src/main/java/subway/station/Station.java index 735a3aa00..b4707ed57 100644 --- a/src/main/java/subway/station/Station.java +++ b/src/main/java/subway/station/Station.java @@ -1,7 +1,8 @@ package subway.station; public class Station { - private String name; + + private final String name; public Station(String name) { this.name = name; @@ -11,5 +12,7 @@ public String getName() { return name; } - // 추가 기능 구현 + public boolean isSame(String name) { + return name.equals(this.name); + } } diff --git a/src/main/java/subway/station/StationRepository.java b/src/main/java/subway/station/StationRepository.java index fa5d932be..d23793b35 100644 --- a/src/main/java/subway/station/StationRepository.java +++ b/src/main/java/subway/station/StationRepository.java @@ -19,4 +19,11 @@ public static void addStation(Station station) { public static boolean deleteStation(String name) { return stations.removeIf(station -> Objects.equals(station.getName(), name)); } + + public static Station findByName(String name) { + return stations.stream() + .filter(station -> station.isSame(name)) + .findAny() + .orElseThrow(); + } } From facf36b88edaa55c721c18cd0640963fde05070d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 00:40:23 +0900 Subject: [PATCH 04/70] =?UTF-8?q?feat(OutputView):=20=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/Application.java | 2 ++ src/main/java/subway/SubwayController.java | 8 ------ .../java/subway/constant/OutputMessage.java | 18 +++++++++++++ .../java/subway/constant/PrintElement.java | 18 +++++++++++++ .../subway/{ => main}/Initialization.java | 2 +- src/main/java/subway/main/MainOption.java | 26 +++++++++++++++++++ .../java/subway/main/SubwayController.java | 13 ++++++++++ src/main/java/subway/view/OutputView.java | 23 ++++++++++++++++ 9 files changed, 102 insertions(+), 10 deletions(-) delete mode 100644 src/main/java/subway/SubwayController.java create mode 100644 src/main/java/subway/constant/OutputMessage.java create mode 100644 src/main/java/subway/constant/PrintElement.java rename src/main/java/subway/{ => main}/Initialization.java (99%) create mode 100644 src/main/java/subway/main/MainOption.java create mode 100644 src/main/java/subway/main/SubwayController.java create mode 100644 src/main/java/subway/view/OutputView.java diff --git a/docs/README.md b/docs/README.md index 4a7bd619c..893951799 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ - [x] 사전 등록 정보 초기 설정 ### 메인 화면 -- [ ] 메인 화면 출력 +- [x] 메인 화면 출력 - [ ] 원하는 기능 입력 ### 역 관리 diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 9a375891f..7305161a8 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -1,5 +1,7 @@ package subway; +import subway.main.SubwayController; + import java.util.Scanner; public class Application { diff --git a/src/main/java/subway/SubwayController.java b/src/main/java/subway/SubwayController.java deleted file mode 100644 index 21c2ebd17..000000000 --- a/src/main/java/subway/SubwayController.java +++ /dev/null @@ -1,8 +0,0 @@ -package subway; - -public class SubwayController { - - public void start() { - Initialization.init(); - } -} diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java new file mode 100644 index 000000000..2dbb175d1 --- /dev/null +++ b/src/main/java/subway/constant/OutputMessage.java @@ -0,0 +1,18 @@ +package subway.constant; + +public enum OutputMessage { + + MAIN_MESSAGE("메인 화면"); + + private static final String PREFIX = "## "; + private final String message; + + OutputMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return PREFIX + message; + } +} diff --git a/src/main/java/subway/constant/PrintElement.java b/src/main/java/subway/constant/PrintElement.java new file mode 100644 index 000000000..07572cb7d --- /dev/null +++ b/src/main/java/subway/constant/PrintElement.java @@ -0,0 +1,18 @@ +package subway.constant; + +public enum PrintElement { + + COMMA(". "), + NEW_LINE("\n"); + + private final String element; + + PrintElement(String element) { + this.element = element; + } + + @Override + public String toString() { + return element; + } +} diff --git a/src/main/java/subway/Initialization.java b/src/main/java/subway/main/Initialization.java similarity index 99% rename from src/main/java/subway/Initialization.java rename to src/main/java/subway/main/Initialization.java index d5cd9f348..0cb8e69b2 100644 --- a/src/main/java/subway/Initialization.java +++ b/src/main/java/subway/main/Initialization.java @@ -1,4 +1,4 @@ -package subway; +package subway.main; import subway.line.Line; import subway.line.LineRepository; diff --git a/src/main/java/subway/main/MainOption.java b/src/main/java/subway/main/MainOption.java new file mode 100644 index 000000000..777735421 --- /dev/null +++ b/src/main/java/subway/main/MainOption.java @@ -0,0 +1,26 @@ +package subway.main; + +public enum MainOption { + STATION_MANAGEMENT("1", "역 관리"), + LINE_MANAGEMENT("2", "노선 관리"), + SECTION_MANAGEMENT("3", "구간 관리"), + SUBWAY_MAP("4", "지하철 노선도 출력"), + QUIT("Q", "종료"); + + + private final String option; + private final String title; + + MainOption(String option, String title) { + this.option = option; + this.title = title; + } + + public String getOption() { + return option; + } + + public String getTitle() { + return title; + } +} diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java new file mode 100644 index 000000000..4fb567ecf --- /dev/null +++ b/src/main/java/subway/main/SubwayController.java @@ -0,0 +1,13 @@ +package subway.main; + +import subway.view.OutputView; + +public class SubwayController { + + OutputView outputView = new OutputView(); + + public void start() { + Initialization.init(); + outputView.printMainOptions(); + } +} diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java new file mode 100644 index 000000000..fc300a959 --- /dev/null +++ b/src/main/java/subway/view/OutputView.java @@ -0,0 +1,23 @@ +package subway.view; + +import subway.constant.OutputMessage; +import subway.constant.PrintElement; +import subway.main.MainOption; + +import java.util.Arrays; + +public class OutputView { + + public void printMainOptions() { + StringBuilder stringBuilder = new StringBuilder(); + Arrays.stream(MainOption.values()) + .forEach(value -> + stringBuilder.append(value.getOption()) + .append(PrintElement.COMMA) + .append(value.getTitle()) + .append(PrintElement.NEW_LINE) + ); + System.out.println(OutputMessage.MAIN_MESSAGE); + System.out.println(stringBuilder); + } +} From b1272f51b3b2d2a55ac2ce4b321c456f632bbf58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 00:59:21 +0900 Subject: [PATCH 05/70] =?UTF-8?q?feat(InputView):=20=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=EC=97=90=EC=84=9C=20=EC=9B=90=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/Application.java | 2 +- .../java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/main/MainOption.java | 9 ++++++++ .../java/subway/main/SubwayController.java | 12 +++++++++- src/main/java/subway/view/InputView.java | 22 +++++++++++++++++++ src/main/java/subway/view/OutputView.java | 8 +++++++ 7 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 src/main/java/subway/view/InputView.java diff --git a/docs/README.md b/docs/README.md index 893951799..e12f5270c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,7 +5,7 @@ ### 메인 화면 - [x] 메인 화면 출력 -- [ ] 원하는 기능 입력 +- [x] 원하는 기능 입력 ### 역 관리 - [ ] 역 관리 화면 출력 diff --git a/src/main/java/subway/Application.java b/src/main/java/subway/Application.java index 7305161a8..e3a924b50 100644 --- a/src/main/java/subway/Application.java +++ b/src/main/java/subway/Application.java @@ -7,7 +7,7 @@ public class Application { public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); - SubwayController controller = new SubwayController(); + SubwayController controller = new SubwayController(scanner); controller.start(); } } diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 2dbb175d1..b1af5fe30 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -2,7 +2,8 @@ public enum OutputMessage { - MAIN_MESSAGE("메인 화면"); + MAIN_MESSAGE("메인 화면"), + OPTION_SELECT("원하는 기능을 선택하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/main/MainOption.java b/src/main/java/subway/main/MainOption.java index 777735421..e78e9ed0d 100644 --- a/src/main/java/subway/main/MainOption.java +++ b/src/main/java/subway/main/MainOption.java @@ -1,5 +1,7 @@ package subway.main; +import java.util.Arrays; + public enum MainOption { STATION_MANAGEMENT("1", "역 관리"), LINE_MANAGEMENT("2", "노선 관리"), @@ -16,6 +18,13 @@ public enum MainOption { this.title = title; } + public static MainOption getMainOption(String option) { + return Arrays.stream(MainOption.values()) + .filter(value -> option.equals(value.option)) + .findAny() + .orElseThrow(); + } + public String getOption() { return option; } diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java index 4fb567ecf..798a9353f 100644 --- a/src/main/java/subway/main/SubwayController.java +++ b/src/main/java/subway/main/SubwayController.java @@ -1,13 +1,23 @@ package subway.main; +import subway.view.InputView; import subway.view.OutputView; +import java.util.Scanner; + public class SubwayController { - OutputView outputView = new OutputView(); + private final OutputView outputView; + private final InputView inputView; + + public SubwayController(Scanner scanner) { + this.outputView = new OutputView(); + this.inputView = new InputView(scanner); + } public void start() { Initialization.init(); outputView.printMainOptions(); + MainOption option = inputView.readOption(); } } diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java new file mode 100644 index 000000000..b1adfa213 --- /dev/null +++ b/src/main/java/subway/view/InputView.java @@ -0,0 +1,22 @@ +package subway.view; + +import subway.main.MainOption; + +import java.util.Scanner; + +public class InputView { + + private final Scanner scanner; + private final OutputView outputView = new OutputView(); + + public InputView(Scanner scanner) { + this.scanner = scanner; + } + + public MainOption readOption() { + outputView.printOptions(); + MainOption option = MainOption.getMainOption(scanner.nextLine()); + outputView.printNewLine(); + return option; + } +} diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index fc300a959..151e4afc4 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -20,4 +20,12 @@ public void printMainOptions() { System.out.println(OutputMessage.MAIN_MESSAGE); System.out.println(stringBuilder); } + + public void printOptions() { + System.out.println(OutputMessage.OPTION_SELECT); + } + + public void printNewLine() { + System.out.println(); + } } From 19155e99bc9b56796587b41966c3e6a0cd67ae3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 01:18:26 +0900 Subject: [PATCH 06/70] =?UTF-8?q?feat(MainOption):=20=EC=A1=B4=EC=9E=AC?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=9D=84=20=EC=9E=85=EB=A0=A5=ED=95=9C=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/main/MainOption.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/subway/main/MainOption.java b/src/main/java/subway/main/MainOption.java index e78e9ed0d..47edc4475 100644 --- a/src/main/java/subway/main/MainOption.java +++ b/src/main/java/subway/main/MainOption.java @@ -1,5 +1,7 @@ package subway.main; +import subway.constant.ExceptionMessage; + import java.util.Arrays; public enum MainOption { @@ -22,7 +24,11 @@ public static MainOption getMainOption(String option) { return Arrays.stream(MainOption.values()) .filter(value -> option.equals(value.option)) .findAny() - .orElseThrow(); + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INVALID_OPTION.toString())); + } + + public boolean isStationManagement() { + return this == MainOption.STATION_MANAGEMENT; } public String getOption() { From 15838253451bee1a78828fd821d5f105c58783fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 01:26:20 +0900 Subject: [PATCH 07/70] =?UTF-8?q?feat(SubwayController):=20=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20=EC=84=A0=ED=83=9D=EC=8B=9C=20?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=20=EA=B8=B0=EB=8A=A5=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/main/SubwayController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java index 798a9353f..71857f5fd 100644 --- a/src/main/java/subway/main/SubwayController.java +++ b/src/main/java/subway/main/SubwayController.java @@ -1,5 +1,6 @@ package subway.main; +import subway.station.StationController; import subway.view.InputView; import subway.view.OutputView; @@ -9,15 +10,24 @@ public class SubwayController { private final OutputView outputView; private final InputView inputView; + private final StationController stationController; public SubwayController(Scanner scanner) { this.outputView = new OutputView(); this.inputView = new InputView(scanner); + this.stationController = new StationController(outputView, inputView); } public void start() { Initialization.init(); outputView.printMainOptions(); MainOption option = inputView.readOption(); + link(option); + } + + private void link(MainOption option) { + if (option.isStationManagement()) { + stationController.start(); + } } } From 2e56c8f6af8eb8f40b505d5cf784825c06d4a004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 01:28:05 +0900 Subject: [PATCH 08/70] =?UTF-8?q?feat(OutputView):=20=EC=97=AD=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=ED=99=94=EB=A9=B4=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 3 ++- .../subway/constant/ExceptionMessage.java | 17 ++++++++++++ .../java/subway/constant/OutputMessage.java | 3 ++- .../subway/station/StationController.java | 19 ++++++++++++++ .../java/subway/station/StationOption.java | 26 +++++++++++++++++++ src/main/java/subway/view/OutputView.java | 14 ++++++++++ 6 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/main/java/subway/constant/ExceptionMessage.java create mode 100644 src/main/java/subway/station/StationController.java create mode 100644 src/main/java/subway/station/StationOption.java diff --git a/docs/README.md b/docs/README.md index e12f5270c..238531e4d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,9 +6,10 @@ ### 메인 화면 - [x] 메인 화면 출력 - [x] 원하는 기능 입력 + - [x] 존재하지 않는 기능을 입력한 경우 예외 발생 ### 역 관리 -- [ ] 역 관리 화면 출력 +- [x] 역 관리 화면 출력 - [ ] 원하는 기능 입력 **역 등록** diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java new file mode 100644 index 000000000..edb972fa3 --- /dev/null +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -0,0 +1,17 @@ +package subway.constant; + +public enum ExceptionMessage { + + INVALID_OPTION("존재하지 않는 기능입니다."); + + private final String message; + + ExceptionMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return message; + } +} diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index b1af5fe30..c5931b0f6 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -3,7 +3,8 @@ public enum OutputMessage { MAIN_MESSAGE("메인 화면"), - OPTION_SELECT("원하는 기능을 선택하세요."); + OPTION_SELECT("원하는 기능을 선택하세요."), + STATION_OPTION_SELECT("역 관리 화면"); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java new file mode 100644 index 000000000..5c5f4ae0c --- /dev/null +++ b/src/main/java/subway/station/StationController.java @@ -0,0 +1,19 @@ +package subway.station; + +import subway.view.InputView; +import subway.view.OutputView; + +public class StationController { + + private final OutputView outputView; + private final InputView inputView; + + public StationController(OutputView outputView, InputView inputView) { + this.outputView = outputView; + this.inputView = inputView; + } + + public void start() { + outputView.printStationOption(); + } +} diff --git a/src/main/java/subway/station/StationOption.java b/src/main/java/subway/station/StationOption.java new file mode 100644 index 000000000..2b75e3d66 --- /dev/null +++ b/src/main/java/subway/station/StationOption.java @@ -0,0 +1,26 @@ +package subway.station; + +public enum StationOption { + + CREATE("1", "역 등록"), + DELETE("2", "역 삭제"), + READ("3", "역 조회"), + BACK("B", "돌아가기"); + + + private final String option; + private final String title; + + StationOption(String option, String title) { + this.option = option; + this.title = title; + } + + public String getOption() { + return option; + } + + public String getTitle() { + return title; + } +} diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 151e4afc4..2c00fbaae 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -3,6 +3,7 @@ import subway.constant.OutputMessage; import subway.constant.PrintElement; import subway.main.MainOption; +import subway.station.StationOption; import java.util.Arrays; @@ -25,6 +26,19 @@ public void printOptions() { System.out.println(OutputMessage.OPTION_SELECT); } + public void printStationOption() { + StringBuilder stringBuilder = new StringBuilder(); + Arrays.stream(StationOption.values()) + .forEach(value -> + stringBuilder.append(value.getOption()) + .append(PrintElement.COMMA) + .append(value.getTitle()) + .append(PrintElement.NEW_LINE) + ); + System.out.println(OutputMessage.MAIN_MESSAGE); + System.out.println(stringBuilder); + } + public void printNewLine() { System.out.println(); } From 4668e885775373cd7faaaf1437ce6e45e3e84102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 20:57:13 +0900 Subject: [PATCH 09/70] =?UTF-8?q?feat(InputView):=20=EC=97=AD=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EC=84=A0=ED=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/station/StationController.java | 1 + src/main/java/subway/station/StationOption.java | 11 +++++++++++ src/main/java/subway/view/InputView.java | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 238531e4d..20e52515a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,7 +10,7 @@ ### 역 관리 - [x] 역 관리 화면 출력 -- [ ] 원하는 기능 입력 +- [x] 원하는 기능 입력 **역 등록** - [ ] 등록할 역 이름 입력 diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index 5c5f4ae0c..650589f14 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -15,5 +15,6 @@ public StationController(OutputView outputView, InputView inputView) { public void start() { outputView.printStationOption(); + StationOption option = inputView.readStationOption(); } } diff --git a/src/main/java/subway/station/StationOption.java b/src/main/java/subway/station/StationOption.java index 2b75e3d66..a36b14dac 100644 --- a/src/main/java/subway/station/StationOption.java +++ b/src/main/java/subway/station/StationOption.java @@ -1,5 +1,9 @@ package subway.station; +import subway.constant.ExceptionMessage; + +import java.util.Arrays; + public enum StationOption { CREATE("1", "역 등록"), @@ -16,6 +20,13 @@ public enum StationOption { this.title = title; } + public static StationOption getStationOption(String option) { + return Arrays.stream(StationOption.values()) + .filter(value -> option.equals(value.option)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INVALID_OPTION.toString())); + } + public String getOption() { return option; } diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index b1adfa213..f50796ec9 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -1,6 +1,7 @@ package subway.view; import subway.main.MainOption; +import subway.station.StationOption; import java.util.Scanner; @@ -19,4 +20,11 @@ public MainOption readOption() { outputView.printNewLine(); return option; } + + public StationOption readStationOption() { + outputView.printOptions(); + StationOption option = StationOption.getStationOption(scanner.nextLine()); + outputView.printNewLine(); + return option; + } } From 44142f1511bd535c27fa4c07fcc65cc194650cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 21:00:23 +0900 Subject: [PATCH 10/70] =?UTF-8?q?feat(StationController):=20=EC=97=AD=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EC=8B=9C=20=ED=95=B4=EB=8B=B9=20=EA=B8=B0=EB=8A=A5=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/station/StationController.java | 6 ++++++ src/main/java/subway/station/StationOption.java | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index 650589f14..89d6affef 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -17,4 +17,10 @@ public void start() { outputView.printStationOption(); StationOption option = inputView.readStationOption(); } + + private void createStation(StationOption option) { + if (option.isCreate()) { + // TODO + } + } } diff --git a/src/main/java/subway/station/StationOption.java b/src/main/java/subway/station/StationOption.java index a36b14dac..6c1718e12 100644 --- a/src/main/java/subway/station/StationOption.java +++ b/src/main/java/subway/station/StationOption.java @@ -27,6 +27,10 @@ public static StationOption getStationOption(String option) { .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INVALID_OPTION.toString())); } + public boolean isCreate() { + return this == CREATE; + } + public String getOption() { return option; } From b7cda1bac8ec5419f6ca468aea63232abc9db67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 21:05:47 +0900 Subject: [PATCH 11/70] =?UTF-8?q?feat(InputView):=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=A0=20=EC=97=AD=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/station/StationController.java | 3 ++- src/main/java/subway/view/InputView.java | 7 +++++++ src/main/java/subway/view/OutputView.java | 4 ++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 20e52515a..46c786c60 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,7 +13,7 @@ - [x] 원하는 기능 입력 **역 등록** -- [ ] 등록할 역 이름 입력 +- [x] 등록할 역 이름 입력 - [ ] 중복된 이름의 역이 있을 경우 예외 발생 - [ ] 역 이름이 2글자 이상이 아닐 경우 예외 발생 - [ ] 등록 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index c5931b0f6..7991eb136 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -4,7 +4,8 @@ public enum OutputMessage { MAIN_MESSAGE("메인 화면"), OPTION_SELECT("원하는 기능을 선택하세요."), - STATION_OPTION_SELECT("역 관리 화면"); + STATION_OPTION_SELECT("역 관리 화면"), + CREATE_STATION("등록할 역 이름을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index 89d6affef..72dd5a300 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -16,11 +16,12 @@ public StationController(OutputView outputView, InputView inputView) { public void start() { outputView.printStationOption(); StationOption option = inputView.readStationOption(); + createStation(option); } private void createStation(StationOption option) { if (option.isCreate()) { - // TODO + String name = inputView.readStationName(); } } } diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index f50796ec9..f77bc7754 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -27,4 +27,11 @@ public StationOption readStationOption() { outputView.printNewLine(); return option; } + + public String readStationName() { + outputView.printStationCreation(); + String name = scanner.nextLine(); + outputView.printNewLine(); + return name; + } } diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 2c00fbaae..0054747b4 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -39,6 +39,10 @@ public void printStationOption() { System.out.println(stringBuilder); } + public void printStationCreation() { + System.out.println(OutputMessage.CREATE_STATION); + } + public void printNewLine() { System.out.println(); } From a6beb30c9b741e7d37d5c63ae07cab2102e56e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 21:12:27 +0900 Subject: [PATCH 12/70] =?UTF-8?q?feat(Name):=20=EC=97=AD=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=9D=B4=202=EA=B8=80=EC=9E=90=20=EC=9D=B4=EC=83=81?= =?UTF-8?q?=EC=9D=B4=20=EC=95=84=EB=8B=90=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/station/Name.java | 20 +++++++++++++++++++ .../subway/station/StationController.java | 2 +- src/main/java/subway/view/InputView.java | 5 +++-- 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/main/java/subway/station/Name.java diff --git a/docs/README.md b/docs/README.md index 46c786c60..dfee6e51d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,7 +15,7 @@ **역 등록** - [x] 등록할 역 이름 입력 - [ ] 중복된 이름의 역이 있을 경우 예외 발생 - - [ ] 역 이름이 2글자 이상이 아닐 경우 예외 발생 + - [x] 역 이름이 2글자 이상이 아닐 경우 예외 발생 - [ ] 등록 - [ ] 등록 완료 안내 출력 diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index edb972fa3..07a882f96 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -2,7 +2,8 @@ public enum ExceptionMessage { - INVALID_OPTION("존재하지 않는 기능입니다."); + INVALID_OPTION("존재하지 않는 기능입니다."), + INVALID_LENGTH("2글자 이상 입력만 가능합니다."); private final String message; diff --git a/src/main/java/subway/station/Name.java b/src/main/java/subway/station/Name.java new file mode 100644 index 000000000..dbf9e29fe --- /dev/null +++ b/src/main/java/subway/station/Name.java @@ -0,0 +1,20 @@ +package subway.station; + +import subway.constant.ExceptionMessage; + +public class Name { + + private static final int MIN_LENGTH = 2; + private final String value; + + public Name(String value) { + validateName(value); + this.value = value; + } + + private void validateName(String value) { + if (value.length() < MIN_LENGTH) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_LENGTH.toString()); + } + } +} diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index 72dd5a300..84a4f01ba 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -21,7 +21,7 @@ public void start() { private void createStation(StationOption option) { if (option.isCreate()) { - String name = inputView.readStationName(); + Name name = inputView.readStationName(); } } } diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index f77bc7754..204448286 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -1,6 +1,7 @@ package subway.view; import subway.main.MainOption; +import subway.station.Name; import subway.station.StationOption; import java.util.Scanner; @@ -28,10 +29,10 @@ public StationOption readStationOption() { return option; } - public String readStationName() { + public Name readStationName() { outputView.printStationCreation(); String name = scanner.nextLine(); outputView.printNewLine(); - return name; + return new Name(name); } } From 46602130f1af8b850dc1d092371f1310b223c21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 21:29:29 +0900 Subject: [PATCH 13/70] =?UTF-8?q?feat(Station):=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/station/Station.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/subway/station/Station.java b/src/main/java/subway/station/Station.java index b4707ed57..c613bb531 100644 --- a/src/main/java/subway/station/Station.java +++ b/src/main/java/subway/station/Station.java @@ -2,17 +2,17 @@ public class Station { - private final String name; + private final Name name; - public Station(String name) { + public Station(Name name) { this.name = name; } - public String getName() { + public Name getName() { return name; } - public boolean isSame(String name) { + public boolean isSame(Name name) { return name.equals(this.name); } } From 15dd286310de904f6f90bd1e2bd19b6bbba529ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 21:30:51 +0900 Subject: [PATCH 14/70] =?UTF-8?q?feat(StationService):=20=EC=97=AD=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/main/Initialization.java | 9 +++++---- src/main/java/subway/station/Name.java | 4 ++++ src/main/java/subway/station/StationController.java | 4 +++- src/main/java/subway/station/StationRepository.java | 6 +++--- src/main/java/subway/station/StationService.java | 8 ++++++++ 6 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 src/main/java/subway/station/StationService.java diff --git a/docs/README.md b/docs/README.md index dfee6e51d..1a786e3c8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,7 +16,7 @@ - [x] 등록할 역 이름 입력 - [ ] 중복된 이름의 역이 있을 경우 예외 발생 - [x] 역 이름이 2글자 이상이 아닐 경우 예외 발생 -- [ ] 등록 +- [x] 등록 - [ ] 등록 완료 안내 출력 **역 삭제** diff --git a/src/main/java/subway/main/Initialization.java b/src/main/java/subway/main/Initialization.java index 0cb8e69b2..921607a40 100644 --- a/src/main/java/subway/main/Initialization.java +++ b/src/main/java/subway/main/Initialization.java @@ -3,6 +3,7 @@ import subway.line.Line; import subway.line.LineRepository; import subway.line.StopStations; +import subway.station.Name; import subway.station.Station; import subway.station.StationRepository; @@ -31,12 +32,12 @@ public static void init() { private static void initStation() { Arrays.stream(STATIONS.split(REGEX)) - .forEach(name -> StationRepository.addStation(new Station(name))); + .forEach(name -> StationRepository.addStation(new Name(name))); } private static void initLineTwo() { List stopStation = Arrays.stream(LINE_TWO_STATIONS.split(REGEX)) - .map(StationRepository::findByName) + .map(name -> StationRepository.findByName(new Name(name))) .collect(Collectors.toList()); Line line = new Line(LINE_TWO, new StopStations(stopStation)); LineRepository.addLine(line); @@ -44,7 +45,7 @@ private static void initLineTwo() { private static void initLineThree() { List stopStation = Arrays.stream(LINE_THREE_STATIONS.split(REGEX)) - .map(StationRepository::findByName) + .map(name -> StationRepository.findByName(new Name(name))) .collect(Collectors.toList()); Line line = new Line(LINE_THREE, new StopStations(stopStation)); LineRepository.addLine(line); @@ -52,7 +53,7 @@ private static void initLineThree() { private static void initLineDX() { List stopStation = Arrays.stream(LINE_DX_STATIONS.split(REGEX)) - .map(StationRepository::findByName) + .map(name -> StationRepository.findByName(new Name(name))) .collect(Collectors.toList()); Line line = new Line(LINE_DX, new StopStations(stopStation)); LineRepository.addLine(line); diff --git a/src/main/java/subway/station/Name.java b/src/main/java/subway/station/Name.java index dbf9e29fe..c06c3b548 100644 --- a/src/main/java/subway/station/Name.java +++ b/src/main/java/subway/station/Name.java @@ -17,4 +17,8 @@ private void validateName(String value) { throw new IllegalArgumentException(ExceptionMessage.INVALID_LENGTH.toString()); } } + + public boolean equals(Name name) { + return value.equals(name.value); + } } diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index 84a4f01ba..a5694688e 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -7,10 +7,12 @@ public class StationController { private final OutputView outputView; private final InputView inputView; + private final StationService stationService; public StationController(OutputView outputView, InputView inputView) { this.outputView = outputView; this.inputView = inputView; + this.stationService = new StationService(); } public void start() { @@ -21,7 +23,7 @@ public void start() { private void createStation(StationOption option) { if (option.isCreate()) { - Name name = inputView.readStationName(); + stationService.create(inputView.readStationName()); } } } diff --git a/src/main/java/subway/station/StationRepository.java b/src/main/java/subway/station/StationRepository.java index d23793b35..969caf48c 100644 --- a/src/main/java/subway/station/StationRepository.java +++ b/src/main/java/subway/station/StationRepository.java @@ -12,15 +12,15 @@ public static List stations() { return Collections.unmodifiableList(stations); } - public static void addStation(Station station) { - stations.add(station); + public static void addStation(Name name) { + stations.add(new Station(name)); } public static boolean deleteStation(String name) { return stations.removeIf(station -> Objects.equals(station.getName(), name)); } - public static Station findByName(String name) { + public static Station findByName(Name name) { return stations.stream() .filter(station -> station.isSame(name)) .findAny() diff --git a/src/main/java/subway/station/StationService.java b/src/main/java/subway/station/StationService.java new file mode 100644 index 000000000..f66e07299 --- /dev/null +++ b/src/main/java/subway/station/StationService.java @@ -0,0 +1,8 @@ +package subway.station; + +public class StationService { + + public void create(Name name) { + StationRepository.addStation(name); + } +} From e49a7f6fbf0336da5e4df2e944db50d37869c6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 21:41:30 +0900 Subject: [PATCH 15/70] =?UTF-8?q?feat(StationRepository):=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=EB=90=9C=20=EC=9D=B4=EB=A6=84=EC=9D=98=20=EC=97=AD?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=88=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../java/subway/constant/ExceptionMessage.java | 3 ++- .../java/subway/station/StationRepository.java | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1a786e3c8..998318472 100644 --- a/docs/README.md +++ b/docs/README.md @@ -14,7 +14,7 @@ **역 등록** - [x] 등록할 역 이름 입력 - - [ ] 중복된 이름의 역이 있을 경우 예외 발생 + - [x] 중복된 이름의 역이 있을 경우 예외 발생 - [x] 역 이름이 2글자 이상이 아닐 경우 예외 발생 - [x] 등록 - [ ] 등록 완료 안내 출력 diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index 07a882f96..0bd5a15ab 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -3,7 +3,8 @@ public enum ExceptionMessage { INVALID_OPTION("존재하지 않는 기능입니다."), - INVALID_LENGTH("2글자 이상 입력만 가능합니다."); + INVALID_LENGTH("2글자 이상 입력만 가능합니다."), + DUPLICATE_STATION("이미 존재하는 역입니다."); private final String message; diff --git a/src/main/java/subway/station/StationRepository.java b/src/main/java/subway/station/StationRepository.java index 969caf48c..5b86addbe 100644 --- a/src/main/java/subway/station/StationRepository.java +++ b/src/main/java/subway/station/StationRepository.java @@ -1,5 +1,7 @@ package subway.station; +import subway.constant.ExceptionMessage; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -13,9 +15,21 @@ public static List stations() { } public static void addStation(Name name) { + validateStation(name); stations.add(new Station(name)); } + private static void validateStation(Name name) { + if (isDuplicateName(name)) { + throw new IllegalArgumentException(ExceptionMessage.DUPLICATE_STATION.toString()); + } + } + + private static boolean isDuplicateName(Name name) { + return stations().stream() + .anyMatch(station -> station.isSame(name)); + } + public static boolean deleteStation(String name) { return stations.removeIf(station -> Objects.equals(station.getName(), name)); } From fb431f38479df1c231659d2a1f0301f0059f8cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 21:52:43 +0900 Subject: [PATCH 16/70] =?UTF-8?q?feat(OutputView):=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=20=EC=95=88=EB=82=B4=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../subway/constant/InformationMessage.java | 18 ++++++++++++++++++ .../java/subway/station/StationController.java | 1 + src/main/java/subway/view/OutputView.java | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/java/subway/constant/InformationMessage.java diff --git a/docs/README.md b/docs/README.md index 998318472..afd4d2ba4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,7 +17,7 @@ - [x] 중복된 이름의 역이 있을 경우 예외 발생 - [x] 역 이름이 2글자 이상이 아닐 경우 예외 발생 - [x] 등록 -- [ ] 등록 완료 안내 출력 +- [x] 등록 완료 안내 출력 **역 삭제** - [ ] 삭제할 역 이름 입력 diff --git a/src/main/java/subway/constant/InformationMessage.java b/src/main/java/subway/constant/InformationMessage.java new file mode 100644 index 000000000..0102d9c32 --- /dev/null +++ b/src/main/java/subway/constant/InformationMessage.java @@ -0,0 +1,18 @@ +package subway.constant; + +public enum InformationMessage { + + COMPLETE_CREATE_STATION("지하철 역이 등록되었습니다."); + + private static final String PREFIX = "[INFO] "; + private final String message; + + InformationMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return PREFIX + message; + } +} diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index a5694688e..b75ebb5f5 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -24,6 +24,7 @@ public void start() { private void createStation(StationOption option) { if (option.isCreate()) { stationService.create(inputView.readStationName()); + outputView.printCompleteStationCreate(); } } } diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 0054747b4..843d8885c 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -1,5 +1,6 @@ package subway.view; +import subway.constant.InformationMessage; import subway.constant.OutputMessage; import subway.constant.PrintElement; import subway.main.MainOption; @@ -43,6 +44,10 @@ public void printStationCreation() { System.out.println(OutputMessage.CREATE_STATION); } + public void printCompleteStationCreate() { + System.out.println(InformationMessage.COMPLETE_CREATE_STATION); + } + public void printNewLine() { System.out.println(); } From ecdee1025e75ee7b9e524a277c68cae41ed99a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 22:06:13 +0900 Subject: [PATCH 17/70] =?UTF-8?q?feat(InputView):=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=A0=20=EC=97=AD=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/view/InputView.java | 7 +++++++ src/main/java/subway/view/OutputView.java | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 7991eb136..56038d936 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -5,7 +5,8 @@ public enum OutputMessage { MAIN_MESSAGE("메인 화면"), OPTION_SELECT("원하는 기능을 선택하세요."), STATION_OPTION_SELECT("역 관리 화면"), - CREATE_STATION("등록할 역 이름을 입력하세요."); + CREATE_STATION("등록할 역 이름을 입력하세요."), + DELETE_STATION("삭제할 역 이름을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index 204448286..c0f7e6b1c 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -35,4 +35,11 @@ public Name readStationName() { outputView.printNewLine(); return new Name(name); } + + public Name readDeleteStationName() { + outputView.printDeleteStation(); + String name = scanner.nextLine(); + outputView.printNewLine(); + return new Name(name); + } } diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 843d8885c..55a1e6160 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -48,6 +48,10 @@ public void printCompleteStationCreate() { System.out.println(InformationMessage.COMPLETE_CREATE_STATION); } + public void printDeleteStation() { + System.out.println(OutputMessage.DELETE_STATION); + } + public void printNewLine() { System.out.println(); } From aa270c3eaa01309a32095c19676de210adfde8df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 22:19:39 +0900 Subject: [PATCH 18/70] =?UTF-8?q?feat(StationRepository):=20=EC=97=AD=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/station/StationController.java | 7 +++++++ src/main/java/subway/station/StationOption.java | 4 ++++ src/main/java/subway/station/StationRepository.java | 6 +++--- src/main/java/subway/station/StationService.java | 4 ++++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index afd4d2ba4..304baf7a8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -20,11 +20,11 @@ - [x] 등록 완료 안내 출력 **역 삭제** -- [ ] 삭제할 역 이름 입력 +- [x] 삭제할 역 이름 입력 - [ ] 존재하지 않는 역일 경우 예외 발생 - [ ] 삭제 - [ ] 노선에 등록된 역일 경우 노선에서 삭제 - - [ ] 역 삭제 + - [x] 역 삭제 - [ ] 삭제 완료 안내 출력 **역 조회** diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index b75ebb5f5..0682ad8b1 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -19,6 +19,7 @@ public void start() { outputView.printStationOption(); StationOption option = inputView.readStationOption(); createStation(option); + deleteStation(option); } private void createStation(StationOption option) { @@ -27,4 +28,10 @@ private void createStation(StationOption option) { outputView.printCompleteStationCreate(); } } + + private void deleteStation(StationOption option) { + if (option.isDelete()) { + stationService.delete(inputView.readDeleteStationName()); + } + } } diff --git a/src/main/java/subway/station/StationOption.java b/src/main/java/subway/station/StationOption.java index 6c1718e12..87f5193e0 100644 --- a/src/main/java/subway/station/StationOption.java +++ b/src/main/java/subway/station/StationOption.java @@ -31,6 +31,10 @@ public boolean isCreate() { return this == CREATE; } + public boolean isDelete() { + return this == DELETE; + } + public String getOption() { return option; } diff --git a/src/main/java/subway/station/StationRepository.java b/src/main/java/subway/station/StationRepository.java index 5b86addbe..327c6a013 100644 --- a/src/main/java/subway/station/StationRepository.java +++ b/src/main/java/subway/station/StationRepository.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; public class StationRepository { private static final List stations = new ArrayList<>(); @@ -30,8 +29,9 @@ private static boolean isDuplicateName(Name name) { .anyMatch(station -> station.isSame(name)); } - public static boolean deleteStation(String name) { - return stations.removeIf(station -> Objects.equals(station.getName(), name)); + public static void deleteStation(Name name) { + Station station = findByName(name); + stations.remove(station); } public static Station findByName(Name name) { diff --git a/src/main/java/subway/station/StationService.java b/src/main/java/subway/station/StationService.java index f66e07299..b0a2e4352 100644 --- a/src/main/java/subway/station/StationService.java +++ b/src/main/java/subway/station/StationService.java @@ -5,4 +5,8 @@ public class StationService { public void create(Name name) { StationRepository.addStation(name); } + + public void delete(Name name) { + StationRepository.deleteStation(name); + } } From d29caf48f6ba62e6bbbb71446591ee7ee067e96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 22:22:55 +0900 Subject: [PATCH 19/70] =?UTF-8?q?feat(StationRepository):=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=97=AD?= =?UTF-8?q?=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/station/StationRepository.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 304baf7a8..858869fee 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,7 +21,7 @@ **역 삭제** - [x] 삭제할 역 이름 입력 - - [ ] 존재하지 않는 역일 경우 예외 발생 + - [x] 존재하지 않는 역일 경우 예외 발생 - [ ] 삭제 - [ ] 노선에 등록된 역일 경우 노선에서 삭제 - [x] 역 삭제 diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index 0bd5a15ab..db885270d 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -4,7 +4,8 @@ public enum ExceptionMessage { INVALID_OPTION("존재하지 않는 기능입니다."), INVALID_LENGTH("2글자 이상 입력만 가능합니다."), - DUPLICATE_STATION("이미 존재하는 역입니다."); + DUPLICATE_STATION("이미 존재하는 역입니다."), + NOT_EXISTENT_STATION("존재하지 않는 역입니다."); private final String message; diff --git a/src/main/java/subway/station/StationRepository.java b/src/main/java/subway/station/StationRepository.java index 327c6a013..6f2c0f0ac 100644 --- a/src/main/java/subway/station/StationRepository.java +++ b/src/main/java/subway/station/StationRepository.java @@ -38,6 +38,6 @@ public static Station findByName(Name name) { return stations.stream() .filter(station -> station.isSame(name)) .findAny() - .orElseThrow(); + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.NOT_EXISTENT_STATION.toString())); } } From f4896416203e98b87399f9126f8ca38cb5d2251b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 22:26:05 +0900 Subject: [PATCH 20/70] =?UTF-8?q?feat(OutputView):=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=20=EC=95=88=EB=82=B4=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/InformationMessage.java | 3 ++- src/main/java/subway/station/StationController.java | 3 ++- src/main/java/subway/view/OutputView.java | 6 +++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 858869fee..9fecc859f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,7 +25,7 @@ - [ ] 삭제 - [ ] 노선에 등록된 역일 경우 노선에서 삭제 - [x] 역 삭제 -- [ ] 삭제 완료 안내 출력 +- [x] 삭제 완료 안내 출력 **역 조회** - [ ] 등록되어 있는 역 목록 출력 diff --git a/src/main/java/subway/constant/InformationMessage.java b/src/main/java/subway/constant/InformationMessage.java index 0102d9c32..e7d64e093 100644 --- a/src/main/java/subway/constant/InformationMessage.java +++ b/src/main/java/subway/constant/InformationMessage.java @@ -2,7 +2,8 @@ public enum InformationMessage { - COMPLETE_CREATE_STATION("지하철 역이 등록되었습니다."); + COMPLETE_CREATE_STATION("지하철 역이 등록되었습니다."), + COMPLETE_DELETE_STATION("지하철 역이 삭제되었습니다."); private static final String PREFIX = "[INFO] "; private final String message; diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index 0682ad8b1..07dc327b1 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -25,13 +25,14 @@ public void start() { private void createStation(StationOption option) { if (option.isCreate()) { stationService.create(inputView.readStationName()); - outputView.printCompleteStationCreate(); + outputView.printCreated(); } } private void deleteStation(StationOption option) { if (option.isDelete()) { stationService.delete(inputView.readDeleteStationName()); + outputView.printDeleted(); } } } diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 55a1e6160..210ef65cd 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -44,7 +44,7 @@ public void printStationCreation() { System.out.println(OutputMessage.CREATE_STATION); } - public void printCompleteStationCreate() { + public void printCreated() { System.out.println(InformationMessage.COMPLETE_CREATE_STATION); } @@ -52,6 +52,10 @@ public void printDeleteStation() { System.out.println(OutputMessage.DELETE_STATION); } + public void printDeleted() { + System.out.println(InformationMessage.COMPLETE_DELETE_STATION); + } + public void printNewLine() { System.out.println(); } From 7ece299185c86bdd573f91929a197e8a5f38b364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 23:18:13 +0900 Subject: [PATCH 21/70] =?UTF-8?q?feat(Station):=20toString=20=EC=9E=AC?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/station/Name.java | 5 +++++ src/main/java/subway/station/Station.java | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/subway/station/Name.java b/src/main/java/subway/station/Name.java index c06c3b548..4d9fc3b9e 100644 --- a/src/main/java/subway/station/Name.java +++ b/src/main/java/subway/station/Name.java @@ -21,4 +21,9 @@ private void validateName(String value) { public boolean equals(Name name) { return value.equals(name.value); } + + @Override + public String toString() { + return value; + } } diff --git a/src/main/java/subway/station/Station.java b/src/main/java/subway/station/Station.java index c613bb531..5197048e9 100644 --- a/src/main/java/subway/station/Station.java +++ b/src/main/java/subway/station/Station.java @@ -1,5 +1,7 @@ package subway.station; +import subway.constant.InformationMessage; + public class Station { private final Name name; @@ -8,11 +10,12 @@ public Station(Name name) { this.name = name; } - public Name getName() { - return name; - } - public boolean isSame(Name name) { return name.equals(this.name); } + + @Override + public String toString() { + return String.format(InformationMessage.STATION_ELEMENT.toString(), name.toString()); + } } From 4efc20b78940ac56ed4c5c255ebc81db95d5e575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 23:18:41 +0900 Subject: [PATCH 22/70] =?UTF-8?q?feat(OutputView):=20=EB=93=B1=EB=A1=9D?= =?UTF-8?q?=EB=90=98=EC=96=B4=20=EC=9E=88=EB=8A=94=20=EC=97=AD=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../java/subway/constant/InformationMessage.java | 3 ++- src/main/java/subway/constant/OutputMessage.java | 3 ++- .../java/subway/station/StationController.java | 7 +++++++ src/main/java/subway/station/StationOption.java | 4 ++++ src/main/java/subway/view/OutputView.java | 14 ++++++++++++++ 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 9fecc859f..1ac9ccd3b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -28,7 +28,7 @@ - [x] 삭제 완료 안내 출력 **역 조회** -- [ ] 등록되어 있는 역 목록 출력 +- [x] 등록되어 있는 역 목록 출력 ### 노선 관리 diff --git a/src/main/java/subway/constant/InformationMessage.java b/src/main/java/subway/constant/InformationMessage.java index e7d64e093..6e82bc201 100644 --- a/src/main/java/subway/constant/InformationMessage.java +++ b/src/main/java/subway/constant/InformationMessage.java @@ -3,7 +3,8 @@ public enum InformationMessage { COMPLETE_CREATE_STATION("지하철 역이 등록되었습니다."), - COMPLETE_DELETE_STATION("지하철 역이 삭제되었습니다."); + COMPLETE_DELETE_STATION("지하철 역이 삭제되었습니다."), + STATION_ELEMENT("%s\n"); private static final String PREFIX = "[INFO] "; private final String message; diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 56038d936..66caf3745 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -6,7 +6,8 @@ public enum OutputMessage { OPTION_SELECT("원하는 기능을 선택하세요."), STATION_OPTION_SELECT("역 관리 화면"), CREATE_STATION("등록할 역 이름을 입력하세요."), - DELETE_STATION("삭제할 역 이름을 입력하세요."); + DELETE_STATION("삭제할 역 이름을 입력하세요."), + READ_STATION("역 목록"); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index 07dc327b1..a17873cb8 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -20,6 +20,7 @@ public void start() { StationOption option = inputView.readStationOption(); createStation(option); deleteStation(option); + printStation(option); } private void createStation(StationOption option) { @@ -35,4 +36,10 @@ private void deleteStation(StationOption option) { outputView.printDeleted(); } } + + private void printStation(StationOption option) { + if (option.isRead()) { + outputView.printStations(); + } + } } diff --git a/src/main/java/subway/station/StationOption.java b/src/main/java/subway/station/StationOption.java index 87f5193e0..ab308668f 100644 --- a/src/main/java/subway/station/StationOption.java +++ b/src/main/java/subway/station/StationOption.java @@ -35,6 +35,10 @@ public boolean isDelete() { return this == DELETE; } + public boolean isRead() { + return this == READ; + } + public String getOption() { return option; } diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 210ef65cd..06f00bf6b 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -4,7 +4,9 @@ import subway.constant.OutputMessage; import subway.constant.PrintElement; import subway.main.MainOption; +import subway.station.Station; import subway.station.StationOption; +import subway.station.StationRepository; import java.util.Arrays; @@ -56,6 +58,18 @@ public void printDeleted() { System.out.println(InformationMessage.COMPLETE_DELETE_STATION); } + public void printStations() { + StringBuilder stringBuilder = new StringBuilder(); + StationRepository.stations() + .forEach(station -> appendStations(stringBuilder, station)); + System.out.println(OutputMessage.READ_STATION); + System.out.println(stringBuilder); + } + + private void appendStations(StringBuilder stringBuilder, Station station) { + stringBuilder.append(station); + } + public void printNewLine() { System.out.println(); } From aa1f2524f1ab67d28cc6133d76dd088ae8909219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 3 Sep 2023 23:31:49 +0900 Subject: [PATCH 23/70] =?UTF-8?q?feat(SubwayController):=20=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=EC=97=90=EC=84=9C=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EA=B4=80=EB=A6=AC=EB=A5=BC=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=ED=95=A0=20=EA=B2=BD=EC=9A=B0=20lineController=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/line/LineController.java | 21 ++++++++ src/main/java/subway/line/LineOption.java | 48 +++++++++++++++++++ src/main/java/subway/main/MainOption.java | 4 ++ .../java/subway/main/SubwayController.java | 14 ++++++ .../subway/view/LineView/LineInputView.java | 12 +++++ .../subway/view/LineView/LineOutputView.java | 4 ++ 6 files changed, 103 insertions(+) create mode 100644 src/main/java/subway/line/LineController.java create mode 100644 src/main/java/subway/line/LineOption.java create mode 100644 src/main/java/subway/view/LineView/LineInputView.java create mode 100644 src/main/java/subway/view/LineView/LineOutputView.java diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java new file mode 100644 index 000000000..2518dc036 --- /dev/null +++ b/src/main/java/subway/line/LineController.java @@ -0,0 +1,21 @@ +package subway.line; + +import subway.view.LineView.LineInputView; +import subway.view.LineView.LineOutputView; + +import java.util.Scanner; + +public class LineController { + + private final LineInputView inputView; + private final LineOutputView outputView; + + public LineController(Scanner scanner) { + this.inputView = new LineInputView(scanner); + this.outputView = new LineOutputView(); + } + + public void start() { + + } +} diff --git a/src/main/java/subway/line/LineOption.java b/src/main/java/subway/line/LineOption.java new file mode 100644 index 000000000..7ce2e792f --- /dev/null +++ b/src/main/java/subway/line/LineOption.java @@ -0,0 +1,48 @@ +package subway.line; + +import subway.constant.ExceptionMessage; + +import java.util.Arrays; + +public enum LineOption { + + CREATE("1", "노선 등록"), + DELETE("2", "노선 삭제"), + READ("3", "노선 조회"), + BACK("B", "돌아가기"); + + private final String option; + private final String title; + + LineOption(String option, String title) { + this.option = option; + this.title = title; + } + + public static LineOption getOption(String option) { + return Arrays.stream(LineOption.values()) + .filter(value -> option.equals(value.option)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INVALID_OPTION.toString())); + } + + public boolean isCreate() { + return this == CREATE; + } + + public boolean isDelete() { + return this == DELETE; + } + + public boolean isRead() { + return this == READ; + } + + public String getOption() { + return option; + } + + public String getTitle() { + return title; + } +} diff --git a/src/main/java/subway/main/MainOption.java b/src/main/java/subway/main/MainOption.java index 47edc4475..9a5b5699a 100644 --- a/src/main/java/subway/main/MainOption.java +++ b/src/main/java/subway/main/MainOption.java @@ -31,6 +31,10 @@ public boolean isStationManagement() { return this == MainOption.STATION_MANAGEMENT; } + public boolean isLineManagement() { + return this == MainOption.LINE_MANAGEMENT; + } + public String getOption() { return option; } diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java index 71857f5fd..38a4485df 100644 --- a/src/main/java/subway/main/SubwayController.java +++ b/src/main/java/subway/main/SubwayController.java @@ -1,5 +1,6 @@ package subway.main; +import subway.line.LineController; import subway.station.StationController; import subway.view.InputView; import subway.view.OutputView; @@ -11,11 +12,13 @@ public class SubwayController { private final OutputView outputView; private final InputView inputView; private final StationController stationController; + private final LineController lineController; public SubwayController(Scanner scanner) { this.outputView = new OutputView(); this.inputView = new InputView(scanner); this.stationController = new StationController(outputView, inputView); + this.lineController = new LineController(scanner); } public void start() { @@ -26,8 +29,19 @@ public void start() { } private void link(MainOption option) { + linkToStationManagement(option); + linkToLineManagement(option); + } + + private void linkToStationManagement(MainOption option) { if (option.isStationManagement()) { stationController.start(); } } + + private void linkToLineManagement(MainOption option) { + if (option.isLineManagement()) { + lineController.start(); + } + } } diff --git a/src/main/java/subway/view/LineView/LineInputView.java b/src/main/java/subway/view/LineView/LineInputView.java new file mode 100644 index 000000000..583cfc5bc --- /dev/null +++ b/src/main/java/subway/view/LineView/LineInputView.java @@ -0,0 +1,12 @@ +package subway.view.LineView; + +import java.util.Scanner; + +public class LineInputView { + + private final Scanner scanner; + + public LineInputView(Scanner scanner) { + this.scanner = scanner; + } +} diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java new file mode 100644 index 000000000..bf11ac6df --- /dev/null +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -0,0 +1,4 @@ +package subway.view.LineView; + +public class LineOutputView { +} From 6d4ff3772f616b38a581b892fd658c92ced6247f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 00:40:06 +0900 Subject: [PATCH 24/70] =?UTF-8?q?feat(OutputView):=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=ED=99=94=EB=A9=B4=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/line/LineController.java | 2 +- .../subway/view/LineView/LineOutputView.java | 19 +++++++++++++++++++ src/main/java/subway/view/OutputView.java | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1ac9ccd3b..a32f1cbea 100644 --- a/docs/README.md +++ b/docs/README.md @@ -32,7 +32,7 @@ ### 노선 관리 -- [ ] 노선 관리 화면 출력 +- [x] 노선 관리 화면 출력 - [ ] 원하는 기능 선택 **노선 등록** diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 66caf3745..95cbbdaa5 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -7,7 +7,8 @@ public enum OutputMessage { STATION_OPTION_SELECT("역 관리 화면"), CREATE_STATION("등록할 역 이름을 입력하세요."), DELETE_STATION("삭제할 역 이름을 입력하세요."), - READ_STATION("역 목록"); + READ_STATION("역 목록"), + LINE_MANAGEMENT_SCREEN("노선 관리 화면"); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 2518dc036..832e5706a 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -16,6 +16,6 @@ public LineController(Scanner scanner) { } public void start() { - + outputView.printLineOption(); } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index bf11ac6df..f1bf2b1f1 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -1,4 +1,23 @@ package subway.view.LineView; +import subway.constant.OutputMessage; +import subway.constant.PrintElement; +import subway.line.LineOption; + +import java.util.Arrays; + public class LineOutputView { + + public void printLineOption() { + StringBuilder stringBuilder = new StringBuilder(); + Arrays.stream(LineOption.values()) + .forEach(value -> + stringBuilder.append(value.getOption()) + .append(PrintElement.COMMA) + .append(value.getTitle()) + .append(PrintElement.NEW_LINE) + ); + System.out.println(OutputMessage.LINE_MANAGEMENT_SCREEN); + System.out.println(stringBuilder); + } } diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 06f00bf6b..ea264179f 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -38,7 +38,7 @@ public void printStationOption() { .append(value.getTitle()) .append(PrintElement.NEW_LINE) ); - System.out.println(OutputMessage.MAIN_MESSAGE); + System.out.println(OutputMessage.STATION_OPTION_SELECT); System.out.println(stringBuilder); } From 3f9cac4c1dbdb1852fb921fc7842a7519554813d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 00:50:09 +0900 Subject: [PATCH 25/70] =?UTF-8?q?feat(LineInputView):=20=EC=9B=90=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=84=A0=ED=83=9D=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/line/LineController.java | 1 + .../java/subway/view/LineView/LineInputView.java | 10 ++++++++++ .../java/subway/view/LineView/LineOutputView.java | 12 ++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index a32f1cbea..cc21966f8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -33,7 +33,7 @@ ### 노선 관리 - [x] 노선 관리 화면 출력 -- [ ] 원하는 기능 선택 +- [x] 원하는 기능 선택 **노선 등록** diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 832e5706a..9a1b5a26f 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -17,5 +17,6 @@ public LineController(Scanner scanner) { public void start() { outputView.printLineOption(); + LineOption option = inputView.readOption(); } } diff --git a/src/main/java/subway/view/LineView/LineInputView.java b/src/main/java/subway/view/LineView/LineInputView.java index 583cfc5bc..2a61eb460 100644 --- a/src/main/java/subway/view/LineView/LineInputView.java +++ b/src/main/java/subway/view/LineView/LineInputView.java @@ -1,12 +1,22 @@ package subway.view.LineView; +import subway.line.LineOption; + import java.util.Scanner; public class LineInputView { private final Scanner scanner; + private final LineOutputView outputView = new LineOutputView(); public LineInputView(Scanner scanner) { this.scanner = scanner; } + + public LineOption readOption() { + outputView.printOptions(); + LineOption option = LineOption.getOption(scanner.nextLine()); + outputView.printNewLine(); + return option; + } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index f1bf2b1f1..1495e7803 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -20,4 +20,16 @@ public void printLineOption() { System.out.println(OutputMessage.LINE_MANAGEMENT_SCREEN); System.out.println(stringBuilder); } + + public void printOptions() { + System.out.println(OutputMessage.OPTION_SELECT); + } + + public void printReadLineName() { + System.out.println(OutputMessage.MAIN_MESSAGE); + } + + public void printNewLine() { + System.out.println(); + } } From f8af5a3e90253cd4521aa1df459970287255caf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 00:53:35 +0900 Subject: [PATCH 26/70] =?UTF-8?q?feat(LineInputView):=20=EB=85=B8=EC=84=A0?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/line/LineController.java | 8 ++++++++ src/main/java/subway/view/LineView/LineInputView.java | 8 ++++++++ src/main/java/subway/view/LineView/LineOutputView.java | 2 +- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index cc21966f8..e58998e00 100644 --- a/docs/README.md +++ b/docs/README.md @@ -37,9 +37,9 @@ **노선 등록** -- [ ] 등록할 노선 이름 입력 +- [x] 등록할 노선 이름 입력 - [ ] 존재하는 노선일 경우 예외 발생 - - [ ] 1글자 이하일 경우 예외 발생 + - [x] 1글자 이하일 경우 예외 발생 - [ ] 상행 종점역 이름 입력 - [ ] 하행 종점역 이름 입력 - [ ] 존재하지 않는 역일 경우 예외 발생 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 95cbbdaa5..e8af96199 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -8,7 +8,8 @@ public enum OutputMessage { CREATE_STATION("등록할 역 이름을 입력하세요."), DELETE_STATION("삭제할 역 이름을 입력하세요."), READ_STATION("역 목록"), - LINE_MANAGEMENT_SCREEN("노선 관리 화면"); + LINE_MANAGEMENT_SCREEN("노선 관리 화면"), + CREATE_LINE("등록할 노선 이름을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 9a1b5a26f..ecda9761a 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -18,5 +18,13 @@ public LineController(Scanner scanner) { public void start() { outputView.printLineOption(); LineOption option = inputView.readOption(); + createLine(option); + } + + public void createLine(LineOption option) { + if (option.isCreate()) { + + inputView.readLineName(); + } } } diff --git a/src/main/java/subway/view/LineView/LineInputView.java b/src/main/java/subway/view/LineView/LineInputView.java index 2a61eb460..acf46a2ef 100644 --- a/src/main/java/subway/view/LineView/LineInputView.java +++ b/src/main/java/subway/view/LineView/LineInputView.java @@ -1,6 +1,7 @@ package subway.view.LineView; import subway.line.LineOption; +import subway.station.Name; import java.util.Scanner; @@ -19,4 +20,11 @@ public LineOption readOption() { outputView.printNewLine(); return option; } + + public Name readLineName() { + outputView.printReadLineName(); + String name = scanner.nextLine(); + outputView.printNewLine(); + return new Name(name); + } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index 1495e7803..b312b7ac7 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -26,7 +26,7 @@ public void printOptions() { } public void printReadLineName() { - System.out.println(OutputMessage.MAIN_MESSAGE); + System.out.println(OutputMessage.CREATE_LINE); } public void printNewLine() { From 2a06844bd09b8b414c000fe5f2bb91e9a7061463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 01:10:23 +0900 Subject: [PATCH 27/70] =?UTF-8?q?feat(LineInputView):=20=EC=83=81=ED=96=89?= =?UTF-8?q?=20=EC=A2=85=EC=A0=90=EC=97=AD=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/line/LineController.java | 6 ++++-- src/main/java/subway/view/LineView/LineInputView.java | 9 +++++++++ src/main/java/subway/view/LineView/LineOutputView.java | 4 ++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index e58998e00..35a350c9a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -40,7 +40,7 @@ - [x] 등록할 노선 이름 입력 - [ ] 존재하는 노선일 경우 예외 발생 - [x] 1글자 이하일 경우 예외 발생 -- [ ] 상행 종점역 이름 입력 +- [x] 상행 종점역 이름 입력 - [ ] 하행 종점역 이름 입력 - [ ] 존재하지 않는 역일 경우 예외 발생 - [ ] 상행 종점역과 하행 종점역이 같을 경우 예외 발생 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index e8af96199..c84ac7e79 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -9,7 +9,8 @@ public enum OutputMessage { DELETE_STATION("삭제할 역 이름을 입력하세요."), READ_STATION("역 목록"), LINE_MANAGEMENT_SCREEN("노선 관리 화면"), - CREATE_LINE("등록할 노선 이름을 입력하세요."); + CREATE_LINE("등록할 노선 이름을 입력하세요."), + UP_BOUND_STATION("등록할 노선의 상행 종점역 이름을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index ecda9761a..79b6398c1 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -1,5 +1,7 @@ package subway.line; +import subway.station.Name; +import subway.station.Station; import subway.view.LineView.LineInputView; import subway.view.LineView.LineOutputView; @@ -23,8 +25,8 @@ public void start() { public void createLine(LineOption option) { if (option.isCreate()) { - - inputView.readLineName(); + Name name = inputView.readLineName(); + Station upBoundStation = inputView.readUpBoundStation(); } } } diff --git a/src/main/java/subway/view/LineView/LineInputView.java b/src/main/java/subway/view/LineView/LineInputView.java index acf46a2ef..6c4faa6da 100644 --- a/src/main/java/subway/view/LineView/LineInputView.java +++ b/src/main/java/subway/view/LineView/LineInputView.java @@ -2,6 +2,8 @@ import subway.line.LineOption; import subway.station.Name; +import subway.station.Station; +import subway.station.StationRepository; import java.util.Scanner; @@ -27,4 +29,11 @@ public Name readLineName() { outputView.printNewLine(); return new Name(name); } + + public Station readUpBoundStation() { + outputView.printUpBoundStation(); + Station station = StationRepository.findByName(new Name(scanner.nextLine())); + outputView.printNewLine(); + return station; + } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index b312b7ac7..a15cb133b 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -29,6 +29,10 @@ public void printReadLineName() { System.out.println(OutputMessage.CREATE_LINE); } + public void printUpBoundStation() { + System.out.println(OutputMessage.UP_BOUND_STATION); + } + public void printNewLine() { System.out.println(); } From 361c1bad36df217ce2b9afa8ff81fa9a638bfa05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 01:13:35 +0900 Subject: [PATCH 28/70] =?UTF-8?q?feat(LineInputView):=20=ED=95=98=ED=96=89?= =?UTF-8?q?=20=EC=A2=85=EC=A0=90=EC=97=AD=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/line/LineController.java | 1 + src/main/java/subway/view/LineView/LineInputView.java | 7 +++++++ src/main/java/subway/view/LineView/LineOutputView.java | 4 ++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 35a350c9a..85e44d245 100644 --- a/docs/README.md +++ b/docs/README.md @@ -41,8 +41,8 @@ - [ ] 존재하는 노선일 경우 예외 발생 - [x] 1글자 이하일 경우 예외 발생 - [x] 상행 종점역 이름 입력 -- [ ] 하행 종점역 이름 입력 - - [ ] 존재하지 않는 역일 경우 예외 발생 +- [x] 하행 종점역 이름 입력 + - [x] 존재하지 않는 역일 경우 예외 발생 - [ ] 상행 종점역과 하행 종점역이 같을 경우 예외 발생 - [ ] 노선 생성 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index c84ac7e79..125d64a99 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -10,7 +10,8 @@ public enum OutputMessage { READ_STATION("역 목록"), LINE_MANAGEMENT_SCREEN("노선 관리 화면"), CREATE_LINE("등록할 노선 이름을 입력하세요."), - UP_BOUND_STATION("등록할 노선의 상행 종점역 이름을 입력하세요."); + UP_BOUND_STATION("등록할 노선의 상행 종점역 이름을 입력하세요."), + DESCENDING_STATION("등록할 노선의 하행 종점역 이름을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 79b6398c1..2d91e4adb 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -27,6 +27,7 @@ public void createLine(LineOption option) { if (option.isCreate()) { Name name = inputView.readLineName(); Station upBoundStation = inputView.readUpBoundStation(); + Station descendingStation = inputView.readDescendingStation(); } } } diff --git a/src/main/java/subway/view/LineView/LineInputView.java b/src/main/java/subway/view/LineView/LineInputView.java index 6c4faa6da..114f94dae 100644 --- a/src/main/java/subway/view/LineView/LineInputView.java +++ b/src/main/java/subway/view/LineView/LineInputView.java @@ -36,4 +36,11 @@ public Station readUpBoundStation() { outputView.printNewLine(); return station; } + + public Station readDescendingStation() { + outputView.printDescendingStation(); + Station station = StationRepository.findByName(new Name(scanner.nextLine())); + outputView.printNewLine(); + return station; + } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index a15cb133b..8bfc02b33 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -33,6 +33,10 @@ public void printUpBoundStation() { System.out.println(OutputMessage.UP_BOUND_STATION); } + public void printDescendingStation() { + System.out.println(OutputMessage.DESCENDING_STATION); + } + public void printNewLine() { System.out.println(); } From 99fd0531fcf0f859afd580098bfb7ed8d6599057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 01:28:55 +0900 Subject: [PATCH 29/70] =?UTF-8?q?feat(LineRepository):=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EC=A0=80=EC=9E=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/line/Line.java | 8 +++++--- src/main/java/subway/line/LineRepository.java | 8 +++++--- src/main/java/subway/line/StopStations.java | 3 ++- src/main/java/subway/main/Initialization.java | 10 +++------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index 59f0b162e..c497f7808 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -1,16 +1,18 @@ package subway.line; +import subway.station.Name; + public class Line { - private final String name; + private final Name name; private final StopStations stopStations; - public Line(String name, StopStations stopStations) { + public Line(Name name, StopStations stopStations) { this.name = name; this.stopStations = stopStations; } - public String getName() { + public Name getName() { return name; } } diff --git a/src/main/java/subway/line/LineRepository.java b/src/main/java/subway/line/LineRepository.java index 9516b39c4..50a836ab4 100644 --- a/src/main/java/subway/line/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -1,5 +1,7 @@ package subway.line; +import subway.station.Name; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -12,11 +14,11 @@ public static List lines() { return Collections.unmodifiableList(lines); } - public static void addLine(Line line) { - lines.add(line); + public static void addLine(Name name, StopStations stations) { + lines.add(new Line(name, stations)); } public static boolean deleteLineByName(String name) { - return lines.removeIf(line -> Objects.equals(line.getName(), name)); + return lines.removeIf(line -> Objects.equals(line, name)); } } diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index edbc35108..b3a2692b9 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -2,6 +2,7 @@ import subway.station.Station; +import java.util.ArrayList; import java.util.List; public class StopStations { @@ -9,6 +10,6 @@ public class StopStations { private final List element; public StopStations(List stations) { - this.element = stations; + this.element = new ArrayList<>(stations); } } diff --git a/src/main/java/subway/main/Initialization.java b/src/main/java/subway/main/Initialization.java index 921607a40..e182382a0 100644 --- a/src/main/java/subway/main/Initialization.java +++ b/src/main/java/subway/main/Initialization.java @@ -1,6 +1,5 @@ package subway.main; -import subway.line.Line; import subway.line.LineRepository; import subway.line.StopStations; import subway.station.Name; @@ -39,23 +38,20 @@ private static void initLineTwo() { List stopStation = Arrays.stream(LINE_TWO_STATIONS.split(REGEX)) .map(name -> StationRepository.findByName(new Name(name))) .collect(Collectors.toList()); - Line line = new Line(LINE_TWO, new StopStations(stopStation)); - LineRepository.addLine(line); + LineRepository.addLine(new Name(LINE_TWO), new StopStations(stopStation)); } private static void initLineThree() { List stopStation = Arrays.stream(LINE_THREE_STATIONS.split(REGEX)) .map(name -> StationRepository.findByName(new Name(name))) .collect(Collectors.toList()); - Line line = new Line(LINE_THREE, new StopStations(stopStation)); - LineRepository.addLine(line); + LineRepository.addLine(new Name(LINE_THREE), new StopStations(stopStation)); } private static void initLineDX() { List stopStation = Arrays.stream(LINE_DX_STATIONS.split(REGEX)) .map(name -> StationRepository.findByName(new Name(name))) .collect(Collectors.toList()); - Line line = new Line(LINE_DX, new StopStations(stopStation)); - LineRepository.addLine(line); + LineRepository.addLine(new Name(LINE_DX), new StopStations(stopStation)); } } From 09bf4d514961500753fa05599d1ae666afc453aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 01:29:18 +0900 Subject: [PATCH 30/70] =?UTF-8?q?feat(LineController):=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/line/LineController.java | 5 ++++- src/main/java/subway/line/LineService.java | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/main/java/subway/line/LineService.java diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 2d91e4adb..48981ebb7 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -11,10 +11,12 @@ public class LineController { private final LineInputView inputView; private final LineOutputView outputView; + private final LineService lineService; public LineController(Scanner scanner) { this.inputView = new LineInputView(scanner); this.outputView = new LineOutputView(); + this.lineService = new LineService(); } public void start() { @@ -25,9 +27,10 @@ public void start() { public void createLine(LineOption option) { if (option.isCreate()) { - Name name = inputView.readLineName(); + Name name = inputView.readLineName(); Station upBoundStation = inputView.readUpBoundStation(); Station descendingStation = inputView.readDescendingStation(); + lineService.create(name, upBoundStation, descendingStation); } } } diff --git a/src/main/java/subway/line/LineService.java b/src/main/java/subway/line/LineService.java new file mode 100644 index 000000000..3e08856bb --- /dev/null +++ b/src/main/java/subway/line/LineService.java @@ -0,0 +1,13 @@ +package subway.line; + +import subway.station.Name; +import subway.station.Station; + +import java.util.List; + +public class LineService { + + public void create(Name name, Station upBoundStation, Station descendingStation) { + LineRepository.addLine(name, new StopStations(List.of(upBoundStation, descendingStation))); + } +} \ No newline at end of file From 39be04c2e7c1a0670de2a18678dbd993462fd0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 01:36:41 +0900 Subject: [PATCH 31/70] =?UTF-8?q?feat(StioStations):=20=EC=83=81=ED=96=89?= =?UTF-8?q?=20=EC=A2=85=EC=A0=90=EC=97=AD=EA=B3=BC=20=ED=95=98=ED=96=89=20?= =?UTF-8?q?=EC=A2=85=EC=A0=90=EC=97=AD=EC=9D=B4=20=EA=B0=99=EC=9D=84=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/line/StopStations.java | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 85e44d245..b81432e34 100644 --- a/docs/README.md +++ b/docs/README.md @@ -43,8 +43,8 @@ - [x] 상행 종점역 이름 입력 - [x] 하행 종점역 이름 입력 - [x] 존재하지 않는 역일 경우 예외 발생 - - [ ] 상행 종점역과 하행 종점역이 같을 경우 예외 발생 -- [ ] 노선 생성 + - [x] 상행 종점역과 하행 종점역이 같을 경우 예외 발생 +- [x] 노선 생성 **노선 삭제** diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index db885270d..74a101d4f 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -5,7 +5,8 @@ public enum ExceptionMessage { INVALID_OPTION("존재하지 않는 기능입니다."), INVALID_LENGTH("2글자 이상 입력만 가능합니다."), DUPLICATE_STATION("이미 존재하는 역입니다."), - NOT_EXISTENT_STATION("존재하지 않는 역입니다."); + NOT_EXISTENT_STATION("존재하지 않는 역입니다."), + DUPLICATE_LAST_STATION("상행 종점 역과 하행 종점역인 다른 역으로 입력되어야 합니다."); private final String message; diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index b3a2692b9..141ad44c4 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -1,15 +1,26 @@ package subway.line; +import subway.constant.ExceptionMessage; import subway.station.Station; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class StopStations { private final List element; public StopStations(List stations) { + validateDuplicate(stations); this.element = new ArrayList<>(stations); } + + private void validateDuplicate(List stations) { + Set checkStation = new HashSet<>(stations); + if (checkStation.size() != stations.size()) { + throw new IllegalArgumentException(ExceptionMessage.DUPLICATE_LAST_STATION.toString()); + } + } } From cd07afcc3b86d22cd2fa72215b3be6f86b0e7011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 01:42:50 +0900 Subject: [PATCH 32/70] =?UTF-8?q?feat(LineRepository):=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=20=EC=A1=B4=EC=9E=AC=ED=95=98=EB=8A=94=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/line/Line.java | 4 ++-- src/main/java/subway/line/LineRepository.java | 13 +++++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index b81432e34..a533fb016 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,7 +38,7 @@ **노선 등록** - [x] 등록할 노선 이름 입력 - - [ ] 존재하는 노선일 경우 예외 발생 + - [x] 존재하는 노선일 경우 예외 발생 - [x] 1글자 이하일 경우 예외 발생 - [x] 상행 종점역 이름 입력 - [x] 하행 종점역 이름 입력 diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index 74a101d4f..d16d12939 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -6,7 +6,8 @@ public enum ExceptionMessage { INVALID_LENGTH("2글자 이상 입력만 가능합니다."), DUPLICATE_STATION("이미 존재하는 역입니다."), NOT_EXISTENT_STATION("존재하지 않는 역입니다."), - DUPLICATE_LAST_STATION("상행 종점 역과 하행 종점역인 다른 역으로 입력되어야 합니다."); + DUPLICATE_LAST_STATION("상행 종점 역과 하행 종점역인 다른 역으로 입력되어야 합니다."), + DUPLICATE_LINE("이미 존재하는 노선입니다."); private final String message; diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index c497f7808..679098e74 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -12,7 +12,7 @@ public Line(Name name, StopStations stopStations) { this.stopStations = stopStations; } - public Name getName() { - return name; + public boolean isSame(Name name) { + return name.equals(this.name); } } diff --git a/src/main/java/subway/line/LineRepository.java b/src/main/java/subway/line/LineRepository.java index 50a836ab4..8a6ebbfea 100644 --- a/src/main/java/subway/line/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -1,5 +1,6 @@ package subway.line; +import subway.constant.ExceptionMessage; import subway.station.Name; import java.util.ArrayList; @@ -15,9 +16,21 @@ public static List lines() { } public static void addLine(Name name, StopStations stations) { + validateStation(name); lines.add(new Line(name, stations)); } + private static void validateStation(Name name) { + if (isDuplicateName(name)) { + throw new IllegalArgumentException(ExceptionMessage.DUPLICATE_LINE.toString()); + } + } + + private static boolean isDuplicateName(Name name) { + return lines.stream() + .anyMatch(line -> line.isSame(name)); + } + public static boolean deleteLineByName(String name) { return lines.removeIf(line -> Objects.equals(line, name)); } From d6c3b9107e6e47c262c48b2caefa7935b5b4ccfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 01:49:44 +0900 Subject: [PATCH 33/70] =?UTF-8?q?feat(OutputView):=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=99=84=EB=A3=8C=20=EC=95=88=EB=82=B4=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 1 + src/main/java/subway/constant/InformationMessage.java | 3 ++- src/main/java/subway/line/LineController.java | 1 + src/main/java/subway/view/LineView/LineOutputView.java | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index a533fb016..32d80321b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -45,6 +45,7 @@ - [x] 존재하지 않는 역일 경우 예외 발생 - [x] 상행 종점역과 하행 종점역이 같을 경우 예외 발생 - [x] 노선 생성 +- [x] 노선 생성 완료 안내 출력 **노선 삭제** diff --git a/src/main/java/subway/constant/InformationMessage.java b/src/main/java/subway/constant/InformationMessage.java index 6e82bc201..87de92660 100644 --- a/src/main/java/subway/constant/InformationMessage.java +++ b/src/main/java/subway/constant/InformationMessage.java @@ -4,7 +4,8 @@ public enum InformationMessage { COMPLETE_CREATE_STATION("지하철 역이 등록되었습니다."), COMPLETE_DELETE_STATION("지하철 역이 삭제되었습니다."), - STATION_ELEMENT("%s\n"); + STATION_ELEMENT("%s\n"), + CREATE_LINE("지하철 노선이 등록되었습니다."); private static final String PREFIX = "[INFO] "; private final String message; diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 48981ebb7..50fa6a442 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -31,6 +31,7 @@ public void createLine(LineOption option) { Station upBoundStation = inputView.readUpBoundStation(); Station descendingStation = inputView.readDescendingStation(); lineService.create(name, upBoundStation, descendingStation); + outputView.printCreateLine(); } } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index 8bfc02b33..0fa36c882 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -1,5 +1,6 @@ package subway.view.LineView; +import subway.constant.InformationMessage; import subway.constant.OutputMessage; import subway.constant.PrintElement; import subway.line.LineOption; @@ -37,6 +38,10 @@ public void printDescendingStation() { System.out.println(OutputMessage.DESCENDING_STATION); } + public void printCreateLine() { + System.out.println(InformationMessage.COMPLETE_CREATE_STATION); + } + public void printNewLine() { System.out.println(); } From 17fbaa423bce357cd33d3bd2665da6d6b6a45b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 01:55:04 +0900 Subject: [PATCH 34/70] =?UTF-8?q?feat(InputView):=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=A0=20=EB=85=B8=EC=84=A0=20=EC=9D=B4=EB=A6=84=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/line/LineController.java | 7 +++++++ src/main/java/subway/view/LineView/LineInputView.java | 7 +++++++ src/main/java/subway/view/LineView/LineOutputView.java | 4 ++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 32d80321b..37beb7777 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,7 +49,7 @@ **노선 삭제** -- [ ] 삭제할 노선 이름 입력 +- [x] 삭제할 노선 이름 입력 - [ ] 존재하지 않는 노선일 경우 예외 발생 - [ ] 노선 삭제 - [ ] 삭제 완료 안내 출력 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 125d64a99..1d0ace053 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -11,7 +11,8 @@ public enum OutputMessage { LINE_MANAGEMENT_SCREEN("노선 관리 화면"), CREATE_LINE("등록할 노선 이름을 입력하세요."), UP_BOUND_STATION("등록할 노선의 상행 종점역 이름을 입력하세요."), - DESCENDING_STATION("등록할 노선의 하행 종점역 이름을 입력하세요."); + DESCENDING_STATION("등록할 노선의 하행 종점역 이름을 입력하세요."), + DELETE_LINE("삭제할 노선 이름을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 50fa6a442..3dd28bba9 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -23,6 +23,7 @@ public void start() { outputView.printLineOption(); LineOption option = inputView.readOption(); createLine(option); + deleteLine(option); } public void createLine(LineOption option) { @@ -34,4 +35,10 @@ public void createLine(LineOption option) { outputView.printCreateLine(); } } + + public void deleteLine(LineOption option) { + if (option.isDelete()) { + inputView.readDeleteStation(); + } + } } diff --git a/src/main/java/subway/view/LineView/LineInputView.java b/src/main/java/subway/view/LineView/LineInputView.java index 114f94dae..57fce2b78 100644 --- a/src/main/java/subway/view/LineView/LineInputView.java +++ b/src/main/java/subway/view/LineView/LineInputView.java @@ -43,4 +43,11 @@ public Station readDescendingStation() { outputView.printNewLine(); return station; } + + public Name readDeleteStation() { + outputView.printReadDeleteLine(); + Name name = new Name(scanner.nextLine()); + outputView.printNewLine(); + return name; + } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index 0fa36c882..600cd3102 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -42,6 +42,10 @@ public void printCreateLine() { System.out.println(InformationMessage.COMPLETE_CREATE_STATION); } + public void printReadDeleteLine() { + System.out.println(OutputMessage.DELETE_LINE); + } + public void printNewLine() { System.out.println(); } From e5427cfc1cf7c30596eaab6eb420815001cd1a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 02:00:50 +0900 Subject: [PATCH 35/70] =?UTF-8?q?feat(LineRepository):=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/line/Line.java | 4 ++++ src/main/java/subway/line/LineController.java | 2 +- src/main/java/subway/line/LineRepository.java | 13 ++++++++++--- src/main/java/subway/line/LineService.java | 4 ++++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index 37beb7777..c195e7b3c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -51,7 +51,7 @@ - [x] 삭제할 노선 이름 입력 - [ ] 존재하지 않는 노선일 경우 예외 발생 -- [ ] 노선 삭제 +- [x] 노선 삭제 - [ ] 삭제 완료 안내 출력 **노선 조회** diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index 679098e74..557d7459e 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -15,4 +15,8 @@ public Line(Name name, StopStations stopStations) { public boolean isSame(Name name) { return name.equals(this.name); } + + public Name getName() { + return name; + } } diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 3dd28bba9..634ac5cf1 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -38,7 +38,7 @@ public void createLine(LineOption option) { public void deleteLine(LineOption option) { if (option.isDelete()) { - inputView.readDeleteStation(); + lineService.delete(inputView.readDeleteStation()); } } } diff --git a/src/main/java/subway/line/LineRepository.java b/src/main/java/subway/line/LineRepository.java index 8a6ebbfea..d42e854c6 100644 --- a/src/main/java/subway/line/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; public class LineRepository { private static final List lines = new ArrayList<>(); @@ -31,7 +30,15 @@ private static boolean isDuplicateName(Name name) { .anyMatch(line -> line.isSame(name)); } - public static boolean deleteLineByName(String name) { - return lines.removeIf(line -> Objects.equals(line, name)); + public static boolean deleteLineByName(Name name) { + Line line = findLineByName(name); + return lines.remove(line); + } + + private static Line findLineByName(Name name) { + return lines.stream() + .filter(line -> line.isSame(name)) + .findAny() + .orElseThrow(); } } diff --git a/src/main/java/subway/line/LineService.java b/src/main/java/subway/line/LineService.java index 3e08856bb..039f541b5 100644 --- a/src/main/java/subway/line/LineService.java +++ b/src/main/java/subway/line/LineService.java @@ -10,4 +10,8 @@ public class LineService { public void create(Name name, Station upBoundStation, Station descendingStation) { LineRepository.addLine(name, new StopStations(List.of(upBoundStation, descendingStation))); } + + public void delete(Name name) { + LineRepository.deleteLineByName(name); + } } \ No newline at end of file From dcc05a23f27890233857ac0d0e9b4f062455b43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 02:03:05 +0900 Subject: [PATCH 36/70] =?UTF-8?q?feat(LineRepository):=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/line/LineRepository.java | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index c195e7b3c..56d71bb85 100644 --- a/docs/README.md +++ b/docs/README.md @@ -50,7 +50,7 @@ **노선 삭제** - [x] 삭제할 노선 이름 입력 - - [ ] 존재하지 않는 노선일 경우 예외 발생 + - [x] 존재하지 않는 노선일 경우 예외 발생 - [x] 노선 삭제 - [ ] 삭제 완료 안내 출력 diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index d16d12939..43f293757 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -7,7 +7,8 @@ public enum ExceptionMessage { DUPLICATE_STATION("이미 존재하는 역입니다."), NOT_EXISTENT_STATION("존재하지 않는 역입니다."), DUPLICATE_LAST_STATION("상행 종점 역과 하행 종점역인 다른 역으로 입력되어야 합니다."), - DUPLICATE_LINE("이미 존재하는 노선입니다."); + DUPLICATE_LINE("이미 존재하는 노선입니다."), + NOT_EXISTENT_LINE("존재하지 않는 노선입니다."); private final String message; diff --git a/src/main/java/subway/line/LineRepository.java b/src/main/java/subway/line/LineRepository.java index d42e854c6..e07bf3ed0 100644 --- a/src/main/java/subway/line/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -30,15 +30,15 @@ private static boolean isDuplicateName(Name name) { .anyMatch(line -> line.isSame(name)); } - public static boolean deleteLineByName(Name name) { + public static void deleteLineByName(Name name) { Line line = findLineByName(name); - return lines.remove(line); + lines.remove(line); } private static Line findLineByName(Name name) { return lines.stream() .filter(line -> line.isSame(name)) .findAny() - .orElseThrow(); + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.NOT_EXISTENT_LINE.toString())); } } From 3f3fa1e52e5dbba2a36c2cfb8a106f0cde8d22b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 02:04:43 +0900 Subject: [PATCH 37/70] =?UTF-8?q?feat(OutputView):=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=20=EC=95=88=EB=82=B4=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/InformationMessage.java | 3 ++- src/main/java/subway/line/LineController.java | 1 + src/main/java/subway/view/LineView/LineOutputView.java | 4 ++++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 56d71bb85..1c9fdab3c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -52,7 +52,7 @@ - [x] 삭제할 노선 이름 입력 - [x] 존재하지 않는 노선일 경우 예외 발생 - [x] 노선 삭제 -- [ ] 삭제 완료 안내 출력 +- [x] 삭제 완료 안내 출력 **노선 조회** - [ ] 노선 목록 출력 diff --git a/src/main/java/subway/constant/InformationMessage.java b/src/main/java/subway/constant/InformationMessage.java index 87de92660..48b7d2e06 100644 --- a/src/main/java/subway/constant/InformationMessage.java +++ b/src/main/java/subway/constant/InformationMessage.java @@ -5,7 +5,8 @@ public enum InformationMessage { COMPLETE_CREATE_STATION("지하철 역이 등록되었습니다."), COMPLETE_DELETE_STATION("지하철 역이 삭제되었습니다."), STATION_ELEMENT("%s\n"), - CREATE_LINE("지하철 노선이 등록되었습니다."); + CREATE_LINE("지하철 노선이 등록되었습니다."), + DELETE_LINE("지하철 노선이 삭제되었습니다."); private static final String PREFIX = "[INFO] "; private final String message; diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 634ac5cf1..7e4b005bc 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -39,6 +39,7 @@ public void createLine(LineOption option) { public void deleteLine(LineOption option) { if (option.isDelete()) { lineService.delete(inputView.readDeleteStation()); + outputView.printDeleteLine(); } } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index 600cd3102..669cb9431 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -46,6 +46,10 @@ public void printReadDeleteLine() { System.out.println(OutputMessage.DELETE_LINE); } + public void printDeleteLine() { + System.out.println(InformationMessage.DELETE_LINE); + } + public void printNewLine() { System.out.println(); } From 40af5015ed0c64464b9cc8e98465bb4d1e0d3fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 02:10:38 +0900 Subject: [PATCH 38/70] =?UTF-8?q?feat(OutputView):=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../java/subway/constant/InformationMessage.java | 2 +- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/line/Line.java | 6 ++++-- src/main/java/subway/line/LineController.java | 7 +++++++ src/main/java/subway/station/Station.java | 2 +- .../java/subway/view/LineView/LineOutputView.java | 14 ++++++++++++++ 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1c9fdab3c..dda9bbf4d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -55,7 +55,7 @@ - [x] 삭제 완료 안내 출력 **노선 조회** -- [ ] 노선 목록 출력 +- [x] 노선 목록 출력 ### 구간 관리 diff --git a/src/main/java/subway/constant/InformationMessage.java b/src/main/java/subway/constant/InformationMessage.java index 48b7d2e06..7d2bb7e89 100644 --- a/src/main/java/subway/constant/InformationMessage.java +++ b/src/main/java/subway/constant/InformationMessage.java @@ -4,7 +4,7 @@ public enum InformationMessage { COMPLETE_CREATE_STATION("지하철 역이 등록되었습니다."), COMPLETE_DELETE_STATION("지하철 역이 삭제되었습니다."), - STATION_ELEMENT("%s\n"), + READ_ELEMENT("%s\n"), CREATE_LINE("지하철 노선이 등록되었습니다."), DELETE_LINE("지하철 노선이 삭제되었습니다."); diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 1d0ace053..58338f9c1 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -12,7 +12,8 @@ public enum OutputMessage { CREATE_LINE("등록할 노선 이름을 입력하세요."), UP_BOUND_STATION("등록할 노선의 상행 종점역 이름을 입력하세요."), DESCENDING_STATION("등록할 노선의 하행 종점역 이름을 입력하세요."), - DELETE_LINE("삭제할 노선 이름을 입력하세요."); + DELETE_LINE("삭제할 노선 이름을 입력하세요."), + READ_LINE("노선 목록"); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index 557d7459e..4d300d094 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -1,5 +1,6 @@ package subway.line; +import subway.constant.InformationMessage; import subway.station.Name; public class Line { @@ -16,7 +17,8 @@ public boolean isSame(Name name) { return name.equals(this.name); } - public Name getName() { - return name; + @Override + public String toString() { + return String.format(InformationMessage.READ_ELEMENT.toString(), name); } } diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 7e4b005bc..23c24c842 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -24,6 +24,7 @@ public void start() { LineOption option = inputView.readOption(); createLine(option); deleteLine(option); + printLines(option); } public void createLine(LineOption option) { @@ -42,4 +43,10 @@ public void deleteLine(LineOption option) { outputView.printDeleteLine(); } } + + public void printLines(LineOption option) { + if (option.isRead()) { + outputView.printLines(); + } + } } diff --git a/src/main/java/subway/station/Station.java b/src/main/java/subway/station/Station.java index 5197048e9..bac540857 100644 --- a/src/main/java/subway/station/Station.java +++ b/src/main/java/subway/station/Station.java @@ -16,6 +16,6 @@ public boolean isSame(Name name) { @Override public String toString() { - return String.format(InformationMessage.STATION_ELEMENT.toString(), name.toString()); + return String.format(InformationMessage.READ_ELEMENT.toString(), name.toString()); } } diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/LineView/LineOutputView.java index 669cb9431..f62b910d0 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/LineView/LineOutputView.java @@ -3,7 +3,9 @@ import subway.constant.InformationMessage; import subway.constant.OutputMessage; import subway.constant.PrintElement; +import subway.line.Line; import subway.line.LineOption; +import subway.line.LineRepository; import java.util.Arrays; @@ -53,4 +55,16 @@ public void printDeleteLine() { public void printNewLine() { System.out.println(); } + + public void printLines() { + StringBuilder stringBuilder = new StringBuilder(); + LineRepository.lines() + .forEach(line -> appendStations(stringBuilder, line)); + System.out.println(OutputMessage.READ_LINE); + System.out.println(stringBuilder); + } + + private void appendStations(StringBuilder stringBuilder, Line line) { + stringBuilder.append(line); + } } From 0c78fc02a821e6238f4728f4a1a9ac8de60a6061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 03:56:52 +0900 Subject: [PATCH 39/70] =?UTF-8?q?feat(SubwayController):=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EA=B4=80=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/main/MainOption.java | 4 ++++ .../java/subway/main/SubwayController.java | 10 ++++++++++ .../subway/section/SectionController.java | 20 +++++++++++++++++++ .../subway/view/section/SectionInputView.java | 12 +++++++++++ .../view/section/SectionOutputView.java | 4 ++++ 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/java/subway/section/SectionController.java create mode 100644 src/main/java/subway/view/section/SectionInputView.java create mode 100644 src/main/java/subway/view/section/SectionOutputView.java diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 58338f9c1..54d4cd120 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -13,7 +13,8 @@ public enum OutputMessage { UP_BOUND_STATION("등록할 노선의 상행 종점역 이름을 입력하세요."), DESCENDING_STATION("등록할 노선의 하행 종점역 이름을 입력하세요."), DELETE_LINE("삭제할 노선 이름을 입력하세요."), - READ_LINE("노선 목록"); + READ_LINE("노선 목록"), + SECTION_MANAGEMENT_SCREEN("구간 관리 화면"); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/main/MainOption.java b/src/main/java/subway/main/MainOption.java index 9a5b5699a..064cdc755 100644 --- a/src/main/java/subway/main/MainOption.java +++ b/src/main/java/subway/main/MainOption.java @@ -35,6 +35,10 @@ public boolean isLineManagement() { return this == MainOption.LINE_MANAGEMENT; } + public boolean isSectionManagement() { + return this == MainOption.SECTION_MANAGEMENT; + } + public String getOption() { return option; } diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java index 38a4485df..a515e272e 100644 --- a/src/main/java/subway/main/SubwayController.java +++ b/src/main/java/subway/main/SubwayController.java @@ -1,6 +1,7 @@ package subway.main; import subway.line.LineController; +import subway.section.SectionController; import subway.station.StationController; import subway.view.InputView; import subway.view.OutputView; @@ -13,12 +14,14 @@ public class SubwayController { private final InputView inputView; private final StationController stationController; private final LineController lineController; + private final SectionController sectionController; public SubwayController(Scanner scanner) { this.outputView = new OutputView(); this.inputView = new InputView(scanner); this.stationController = new StationController(outputView, inputView); this.lineController = new LineController(scanner); + this.sectionController = new SectionController(scanner); } public void start() { @@ -31,6 +34,7 @@ public void start() { private void link(MainOption option) { linkToStationManagement(option); linkToLineManagement(option); + linkToSectionManagement(option); } private void linkToStationManagement(MainOption option) { @@ -44,4 +48,10 @@ private void linkToLineManagement(MainOption option) { lineController.start(); } } + + private void linkToSectionManagement(MainOption option) { + if (option.isSectionManagement()) { + sectionController.start(); + } + } } diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java new file mode 100644 index 000000000..52b9e502a --- /dev/null +++ b/src/main/java/subway/section/SectionController.java @@ -0,0 +1,20 @@ +package subway.section; + +import subway.view.section.SectionInputView; +import subway.view.section.SectionOutputView; + +import java.util.Scanner; + +public class SectionController { + + private final SectionInputView inputView; + private final SectionOutputView outputView; + + public SectionController(Scanner scanner) { + this.inputView = new SectionInputView(scanner); + this.outputView = new SectionOutputView(); + } + + public void start() { + } +} diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java new file mode 100644 index 000000000..44aca5299 --- /dev/null +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -0,0 +1,12 @@ +package subway.view.section; + +import java.util.Scanner; + +public class SectionInputView { + + private final Scanner scanner; + + public SectionInputView(Scanner scanner) { + this.scanner = scanner; + } +} diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java new file mode 100644 index 000000000..1fdd81715 --- /dev/null +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -0,0 +1,4 @@ +package subway.view.section; + +public class SectionOutputView { +} From 78d1350a866e4d3a1d5822ce110337805f33c242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 04:00:14 +0900 Subject: [PATCH 40/70] =?UTF-8?q?feat(SectionOption):=20=EA=B5=AC=EA=B0=84?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=84=A0=ED=83=9D=EC=A7=80=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/subway/section/SectionOption.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/subway/section/SectionOption.java diff --git a/src/main/java/subway/section/SectionOption.java b/src/main/java/subway/section/SectionOption.java new file mode 100644 index 000000000..3747612b6 --- /dev/null +++ b/src/main/java/subway/section/SectionOption.java @@ -0,0 +1,44 @@ +package subway.section; + +import subway.constant.ExceptionMessage; + +import java.util.Arrays; + +public enum SectionOption { + + CREATE("1", "구간 등록"), + DELETE("2", "구간 삭제"), + + BACK("B", "돌아가기"); + + private final String option; + private final String title; + + SectionOption(String option, String title) { + this.option = option; + this.title = title; + } + + public static SectionOption getOption(String option) { + return Arrays.stream(SectionOption.values()) + .filter(value -> option.equals(value.option)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INVALID_OPTION.toString())); + } + + public boolean isCreate() { + return this == CREATE; + } + + public boolean isDelete() { + return this == DELETE; + } + + public String getOption() { + return option; + } + + public String getTitle() { + return title; + } +} From 7d44170705412342a3d2d6ed63e74c680bc155f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 04:05:42 +0900 Subject: [PATCH 41/70] =?UTF-8?q?feat(SectionOutputView):=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EA=B4=80=EB=A6=AC=20=ED=99=94=EB=A9=B4=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../subway/section/SectionController.java | 1 + .../view/section/SectionOutputView.java | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index dda9bbf4d..208deb99b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -59,7 +59,7 @@ ### 구간 관리 -- [ ] 구간 관리 화면 출력 +- [x] 구간 관리 화면 출력 - [ ] 원하는 기능 선택 **구간 등록** diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java index 52b9e502a..6ece1ae4d 100644 --- a/src/main/java/subway/section/SectionController.java +++ b/src/main/java/subway/section/SectionController.java @@ -16,5 +16,6 @@ public SectionController(Scanner scanner) { } public void start() { + outputView.printSectionOption(); } } diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index 1fdd81715..05e251f35 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -1,4 +1,26 @@ package subway.view.section; +import subway.constant.OutputMessage; +import subway.constant.PrintElement; +import subway.section.SectionOption; +import subway.station.StationOption; + +import java.util.Arrays; + public class SectionOutputView { + + public void printSectionOption() { + StringBuilder stringBuilder = new StringBuilder(); + Arrays.stream(SectionOption.values()) + .forEach(value -> appendValue(stringBuilder, value)); + System.out.println(OutputMessage.STATION_OPTION_SELECT); + System.out.println(stringBuilder); + } + + private void appendValue(StringBuilder stringBuilder, SectionOption option) { + stringBuilder.append(option.getOption()) + .append(PrintElement.COMMA) + .append(option.getTitle()) + .append(PrintElement.NEW_LINE); + } } From fc885bda49df21bfa78e1c90fc670e1f22e22668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 04:09:24 +0900 Subject: [PATCH 42/70] =?UTF-8?q?feat(SectionOutputView):=20=EC=9B=90?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/section/SectionController.java | 1 + .../java/subway/view/section/SectionInputView.java | 10 ++++++++++ .../java/subway/view/section/SectionOutputView.java | 9 ++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 208deb99b..a285807e0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -60,7 +60,7 @@ ### 구간 관리 - [x] 구간 관리 화면 출력 -- [ ] 원하는 기능 선택 +- [x] 원하는 기능 선택 **구간 등록** diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java index 6ece1ae4d..555282d8d 100644 --- a/src/main/java/subway/section/SectionController.java +++ b/src/main/java/subway/section/SectionController.java @@ -17,5 +17,6 @@ public SectionController(Scanner scanner) { public void start() { outputView.printSectionOption(); + inputView.readOption(); } } diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index 44aca5299..0029d532d 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -1,12 +1,22 @@ package subway.view.section; +import subway.section.SectionOption; + import java.util.Scanner; public class SectionInputView { private final Scanner scanner; + private final SectionOutputView outputView = new SectionOutputView(); public SectionInputView(Scanner scanner) { this.scanner = scanner; } + + public SectionOption readOption() { + outputView.printOptions(); + SectionOption option = SectionOption.getOption(scanner.nextLine()); + outputView.printNewLine(); + return option; + } } diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index 05e251f35..a735ebee3 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -3,7 +3,6 @@ import subway.constant.OutputMessage; import subway.constant.PrintElement; import subway.section.SectionOption; -import subway.station.StationOption; import java.util.Arrays; @@ -23,4 +22,12 @@ private void appendValue(StringBuilder stringBuilder, SectionOption option) { .append(option.getTitle()) .append(PrintElement.NEW_LINE); } + + public void printOptions() { + System.out.println(OutputMessage.OPTION_SELECT); + } + + public void printNewLine() { + System.out.println(); + } } From 071cb514c8d246e3262d527eb17757351f410363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 04:17:26 +0900 Subject: [PATCH 43/70] =?UTF-8?q?feat(SectionInputView):=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/view/section/SectionInputView.java | 8 ++++++++ src/main/java/subway/view/section/SectionOutputView.java | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index a285807e0..8247a3bb5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -64,12 +64,12 @@ **구간 등록** -- [ ] 노선 이름 입력 +- [x] 노선 이름 입력 - [ ] 존재하지 않을 경우 예외 발생 - [ ] 역 이름 입력 - [ ] 존재하지 않을 경우 예외 발생 - [ ] 이미 구간에 존재하는 역일 경우 예외 발생 -- 순서 입력 +- [ ] 순서 입력 - [ ] 범위를 벗어날 경우 예외 발생 - [ ] 구간 등록 - [ ] 등록 완료 안내 출력 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 54d4cd120..fa9415fe6 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -14,7 +14,8 @@ public enum OutputMessage { DESCENDING_STATION("등록할 노선의 하행 종점역 이름을 입력하세요."), DELETE_LINE("삭제할 노선 이름을 입력하세요."), READ_LINE("노선 목록"), - SECTION_MANAGEMENT_SCREEN("구간 관리 화면"); + SECTION_MANAGEMENT_SCREEN("구간 관리 화면"), + SECTION_LINE("노선을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index 0029d532d..bfb409bbe 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -1,6 +1,7 @@ package subway.view.section; import subway.section.SectionOption; +import subway.station.Name; import java.util.Scanner; @@ -19,4 +20,11 @@ public SectionOption readOption() { outputView.printNewLine(); return option; } + + public Name readLineName() { + outputView.printReadLineName(); + String name = scanner.nextLine(); + outputView.printNewLine(); + return new Name(name); + } } diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index a735ebee3..27cc67a17 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -27,6 +27,9 @@ public void printOptions() { System.out.println(OutputMessage.OPTION_SELECT); } + public void printReadLineName() { + System.out.println(OutputMessage.SECTION_LINE); + } public void printNewLine() { System.out.println(); } From 3308a26640121cf046ba11ca5425d18c67fe91fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 04:23:54 +0900 Subject: [PATCH 44/70] =?UTF-8?q?feat(SectionInputView):=20=EC=97=AD=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/view/section/SectionInputView.java | 9 +++++++++ src/main/java/subway/view/section/SectionOutputView.java | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8247a3bb5..d91cccd2e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -66,8 +66,8 @@ - [x] 노선 이름 입력 - [ ] 존재하지 않을 경우 예외 발생 -- [ ] 역 이름 입력 - - [ ] 존재하지 않을 경우 예외 발생 +- [x] 역 이름 입력 + - [x] 존재하지 않을 경우 예외 발생 - [ ] 이미 구간에 존재하는 역일 경우 예외 발생 - [ ] 순서 입력 - [ ] 범위를 벗어날 경우 예외 발생 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index fa9415fe6..fa4e7dc9c 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -15,7 +15,8 @@ public enum OutputMessage { DELETE_LINE("삭제할 노선 이름을 입력하세요."), READ_LINE("노선 목록"), SECTION_MANAGEMENT_SCREEN("구간 관리 화면"), - SECTION_LINE("노선을 입력하세요."); + SECTION_LINE("노선을 입력하세요."), + SECTION_STATION("역이름을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index bfb409bbe..35093b697 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -2,6 +2,8 @@ import subway.section.SectionOption; import subway.station.Name; +import subway.station.Station; +import subway.station.StationRepository; import java.util.Scanner; @@ -27,4 +29,11 @@ public Name readLineName() { outputView.printNewLine(); return new Name(name); } + + public Station readStationName() { + outputView.printReadStationName(); + Name name = new Name(scanner.nextLine()); + outputView.printReadLineName(); + return StationRepository.findByName(name); + } } diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index 27cc67a17..b5ac6d26f 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -30,6 +30,11 @@ public void printOptions() { public void printReadLineName() { System.out.println(OutputMessage.SECTION_LINE); } + + public void printReadStationName() { + System.out.println(OutputMessage.SECTION_STATION); + } + public void printNewLine() { System.out.println(); } From e0593249c5307476c7c36815ef1aa62652eb02f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 04:28:45 +0900 Subject: [PATCH 45/70] =?UTF-8?q?feat(SectionInputView):=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EC=88=9C=EC=84=9C=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/view/section/SectionInputView.java | 9 ++++++++- src/main/java/subway/view/section/SectionOutputView.java | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index fa4e7dc9c..a6669d7c5 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -16,7 +16,8 @@ public enum OutputMessage { READ_LINE("노선 목록"), SECTION_MANAGEMENT_SCREEN("구간 관리 화면"), SECTION_LINE("노선을 입력하세요."), - SECTION_STATION("역이름을 입력하세요."); + SECTION_STATION("역이름을 입력하세요."), + SECTION_INDEX("순서를 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index 35093b697..bd46ff9f3 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -33,7 +33,14 @@ public Name readLineName() { public Station readStationName() { outputView.printReadStationName(); Name name = new Name(scanner.nextLine()); - outputView.printReadLineName(); + outputView.printNewLine(); return StationRepository.findByName(name); } + + public int readIndex() { + outputView.printReadIndex(); + int index = scanner.nextInt(); + outputView.printNewLine(); + return index; + } } diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index b5ac6d26f..787fcae0c 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -35,6 +35,10 @@ public void printReadStationName() { System.out.println(OutputMessage.SECTION_STATION); } + public void printReadIndex() { + System.out.println(OutputMessage.SECTION_INDEX); + } + public void printNewLine() { System.out.println(); } From fa0a34539f52a07edb6c25284056925e024f3ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 13:57:12 +0900 Subject: [PATCH 46/70] =?UTF-8?q?refactor(SectionInputView):=20=EC=97=AD?= =?UTF-8?q?=20=EC=9E=85=EB=A0=A5=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EA=B0=92=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/view/section/SectionInputView.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index bd46ff9f3..3e436716f 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -2,8 +2,6 @@ import subway.section.SectionOption; import subway.station.Name; -import subway.station.Station; -import subway.station.StationRepository; import java.util.Scanner; @@ -30,11 +28,11 @@ public Name readLineName() { return new Name(name); } - public Station readStationName() { + public Name readStationName() { outputView.printReadStationName(); - Name name = new Name(scanner.nextLine()); + String name = scanner.nextLine(); outputView.printNewLine(); - return StationRepository.findByName(name); + return new Name(name); } public int readIndex() { From 4d276c19773eb16ae587696417157274f7c9eb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 14:00:13 +0900 Subject: [PATCH 47/70] =?UTF-8?q?feat(LineRepository):=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EC=B6=94=EA=B0=80=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/line/Line.java | 5 +++++ src/main/java/subway/line/LineRepository.java | 6 ++++++ src/main/java/subway/line/StopStations.java | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index d91cccd2e..d5a8c4027 100644 --- a/docs/README.md +++ b/docs/README.md @@ -69,9 +69,9 @@ - [x] 역 이름 입력 - [x] 존재하지 않을 경우 예외 발생 - [ ] 이미 구간에 존재하는 역일 경우 예외 발생 -- [ ] 순서 입력 +현- [x] 순서 입력 - [ ] 범위를 벗어날 경우 예외 발생 -- [ ] 구간 등록 +- [x] 구간 등록 - [ ] 등록 완료 안내 출력 **구간 삭제** diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index 4d300d094..456f4df93 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -2,6 +2,7 @@ import subway.constant.InformationMessage; import subway.station.Name; +import subway.station.Station; public class Line { @@ -17,6 +18,10 @@ public boolean isSame(Name name) { return name.equals(this.name); } + public void addStopStation(Station station, int index) { + stopStations.addStation(station, index); + } + @Override public String toString() { return String.format(InformationMessage.READ_ELEMENT.toString(), name); diff --git a/src/main/java/subway/line/LineRepository.java b/src/main/java/subway/line/LineRepository.java index e07bf3ed0..65aa6434c 100644 --- a/src/main/java/subway/line/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -2,6 +2,7 @@ import subway.constant.ExceptionMessage; import subway.station.Name; +import subway.station.Station; import java.util.ArrayList; import java.util.Collections; @@ -35,6 +36,11 @@ public static void deleteLineByName(Name name) { lines.remove(line); } + public static void addStopStation(Name lineName, Station station, int index) { + Line line = findLineByName(lineName); + line.addStopStation(station, index); + } + private static Line findLineByName(Name name) { return lines.stream() .filter(line -> line.isSame(name)) diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index 141ad44c4..ea998705e 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -10,6 +10,8 @@ public class StopStations { + private static final int START_INDEX = 1; + private final List element; public StopStations(List stations) { @@ -23,4 +25,8 @@ private void validateDuplicate(List stations) { throw new IllegalArgumentException(ExceptionMessage.DUPLICATE_LAST_STATION.toString()); } } + + public void addStation(Station station, int index) { + element.add(index - START_INDEX, station); + } } From 3e684e160c187906f27882a641169f7bac242413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 14:11:21 +0900 Subject: [PATCH 48/70] =?UTF-8?q?feat(StopStations):=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=20=EA=B5=AC=EA=B0=84=EC=97=90=20=EC=A1=B4=EC=9E=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=97=AD=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/line/StopStations.java | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index d5a8c4027..108de10aa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -68,7 +68,7 @@ - [ ] 존재하지 않을 경우 예외 발생 - [x] 역 이름 입력 - [x] 존재하지 않을 경우 예외 발생 - - [ ] 이미 구간에 존재하는 역일 경우 예외 발생 + - [x] 이미 구간에 존재하는 역일 경우 예외 발생 현- [x] 순서 입력 - [ ] 범위를 벗어날 경우 예외 발생 - [x] 구간 등록 diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index 43f293757..999ea1dd4 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -8,7 +8,8 @@ public enum ExceptionMessage { NOT_EXISTENT_STATION("존재하지 않는 역입니다."), DUPLICATE_LAST_STATION("상행 종점 역과 하행 종점역인 다른 역으로 입력되어야 합니다."), DUPLICATE_LINE("이미 존재하는 노선입니다."), - NOT_EXISTENT_LINE("존재하지 않는 노선입니다."); + NOT_EXISTENT_LINE("존재하지 않는 노선입니다."), + EXISTING_SECTION("해당 노선에 이미 존재하는 역입니다."); private final String message; diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index ea998705e..5a5c1ca85 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -27,6 +27,17 @@ private void validateDuplicate(List stations) { } public void addStation(Station station, int index) { + validateStation(station); element.add(index - START_INDEX, station); } + + public void validateStation(Station station) { + validateExistingStation(station); + } + + private void validateExistingStation(Station station) { + if (element.contains(station)) { + throw new IllegalArgumentException(ExceptionMessage.EXISTING_SECTION.toString()); + } + } } From 965305f67efcf9934d3b76f08497630629711461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 14:23:37 +0900 Subject: [PATCH 49/70] =?UTF-8?q?feat(StopStations):=20=EC=88=9C=EC=84=9C?= =?UTF-8?q?=EA=B0=80=20=EB=B2=94=EC=9C=84=EB=A5=BC=20=EB=B2=97=EC=96=B4?= =?UTF-8?q?=EB=82=A0=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/line/StopStations.java | 11 +++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index 108de10aa..50e6cf33b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -65,12 +65,12 @@ **구간 등록** - [x] 노선 이름 입력 - - [ ] 존재하지 않을 경우 예외 발생 + - [x] 존재하지 않을 경우 예외 발생 - [x] 역 이름 입력 - [x] 존재하지 않을 경우 예외 발생 - [x] 이미 구간에 존재하는 역일 경우 예외 발생 현- [x] 순서 입력 - - [ ] 범위를 벗어날 경우 예외 발생 + - [x] 범위를 벗어날 경우 예외 발생 - [x] 구간 등록 - [ ] 등록 완료 안내 출력 diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index 999ea1dd4..37406b46f 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -9,7 +9,8 @@ public enum ExceptionMessage { DUPLICATE_LAST_STATION("상행 종점 역과 하행 종점역인 다른 역으로 입력되어야 합니다."), DUPLICATE_LINE("이미 존재하는 노선입니다."), NOT_EXISTENT_LINE("존재하지 않는 노선입니다."), - EXISTING_SECTION("해당 노선에 이미 존재하는 역입니다."); + EXISTING_SECTION("해당 노선에 이미 존재하는 역입니다."), + OUT_OF_RANGE("해당 순서에 역을 추가할 수 없습니다."); private final String message; diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index 5a5c1ca85..abc3426e8 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -27,12 +27,13 @@ private void validateDuplicate(List stations) { } public void addStation(Station station, int index) { - validateStation(station); + validateStation(station, index); element.add(index - START_INDEX, station); } - public void validateStation(Station station) { + public void validateStation(Station station , int index) { validateExistingStation(station); + validateRange(index); } private void validateExistingStation(Station station) { @@ -40,4 +41,10 @@ private void validateExistingStation(Station station) { throw new IllegalArgumentException(ExceptionMessage.EXISTING_SECTION.toString()); } } + + private void validateRange(int index) { + if (!(1 <= index && index <= element.size())) { + throw new IllegalArgumentException(ExceptionMessage.OUT_OF_RANGE.toString()); + } + } } From de4f781c4ad55f3525b0a24422e217f92592b78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 14:29:50 +0900 Subject: [PATCH 50/70] =?UTF-8?q?feat(SectionOutputView):=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EB=93=B1=EB=A1=9D=20=EC=99=84=EB=A3=8C=20=EC=95=88?= =?UTF-8?q?=EB=82=B4=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/constant/InformationMessage.java | 3 ++- src/main/java/subway/view/section/SectionOutputView.java | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/subway/constant/InformationMessage.java b/src/main/java/subway/constant/InformationMessage.java index 7d2bb7e89..ec96ededc 100644 --- a/src/main/java/subway/constant/InformationMessage.java +++ b/src/main/java/subway/constant/InformationMessage.java @@ -6,7 +6,8 @@ public enum InformationMessage { COMPLETE_DELETE_STATION("지하철 역이 삭제되었습니다."), READ_ELEMENT("%s\n"), CREATE_LINE("지하철 노선이 등록되었습니다."), - DELETE_LINE("지하철 노선이 삭제되었습니다."); + DELETE_LINE("지하철 노선이 삭제되었습니다."), + CREATE_SECTION("구간이 등록되었습니다."); private static final String PREFIX = "[INFO] "; private final String message; diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index 787fcae0c..2970de293 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -1,5 +1,6 @@ package subway.view.section; +import subway.constant.InformationMessage; import subway.constant.OutputMessage; import subway.constant.PrintElement; import subway.section.SectionOption; @@ -39,6 +40,10 @@ public void printReadIndex() { System.out.println(OutputMessage.SECTION_INDEX); } + public void printCreateSection() { + System.out.println(InformationMessage.CREATE_SECTION); + } + public void printNewLine() { System.out.println(); } From 0f779630dd920e2e302e064663989c4ba03b157a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 14:30:43 +0900 Subject: [PATCH 51/70] =?UTF-8?q?feat(SectionController):=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5=20=EC=A7=84?= =?UTF-8?q?=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- .../java/subway/section/SectionController.java | 16 +++++++++++++++- src/main/java/subway/section/SectionService.java | 12 ++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/main/java/subway/section/SectionService.java diff --git a/docs/README.md b/docs/README.md index 50e6cf33b..df5c51f2a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -69,10 +69,10 @@ - [x] 역 이름 입력 - [x] 존재하지 않을 경우 예외 발생 - [x] 이미 구간에 존재하는 역일 경우 예외 발생 -현- [x] 순서 입력 +- [x] 순서 입력 - [x] 범위를 벗어날 경우 예외 발생 - [x] 구간 등록 -- [ ] 등록 완료 안내 출력 +- [x] 등록 완료 안내 출력 **구간 삭제** diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java index 555282d8d..39b92287e 100644 --- a/src/main/java/subway/section/SectionController.java +++ b/src/main/java/subway/section/SectionController.java @@ -1,5 +1,6 @@ package subway.section; +import subway.station.Name; import subway.view.section.SectionInputView; import subway.view.section.SectionOutputView; @@ -9,14 +10,27 @@ public class SectionController { private final SectionInputView inputView; private final SectionOutputView outputView; + private final SectionService sectionService; public SectionController(Scanner scanner) { this.inputView = new SectionInputView(scanner); this.outputView = new SectionOutputView(); + this.sectionService = new SectionService(); } public void start() { outputView.printSectionOption(); - inputView.readOption(); + SectionOption option = inputView.readOption(); + createSection(option); + } + + private void createSection(SectionOption option) { + if (option.isCreate()) { + Name lineName = inputView.readLineName(); + Name stationName = inputView.readStationName(); + int index = inputView.readIndex(); + sectionService.create(lineName, stationName, index); + outputView.printCreateSection(); + } } } diff --git a/src/main/java/subway/section/SectionService.java b/src/main/java/subway/section/SectionService.java new file mode 100644 index 000000000..cdd7b3788 --- /dev/null +++ b/src/main/java/subway/section/SectionService.java @@ -0,0 +1,12 @@ +package subway.section; + +import subway.line.LineRepository; +import subway.station.Name; +import subway.station.StationRepository; + +public class SectionService { + + public void create(Name lineName, Name stationName, int index) { + LineRepository.addStopStation(lineName, StationRepository.findByName(stationName), index); + } +} \ No newline at end of file From eb4db53843049ae9d7ad58c6a67b1957bd8c0915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 14:38:59 +0900 Subject: [PATCH 52/70] =?UTF-8?q?feat(InputView):=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=A0=20=EA=B5=AC=EA=B0=84=EC=9D=98=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/view/section/SectionInputView.java | 7 +++++++ src/main/java/subway/view/section/SectionOutputView.java | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index df5c51f2a..34ae71444 100644 --- a/docs/README.md +++ b/docs/README.md @@ -76,8 +76,8 @@ **구간 삭제** -- [ ] 삭제할 노선 입력 - - [ ] 존재하지 않는 노선일 경우 예외 발생 +- [x] 삭제할 노선 입력 + - [x] 존재하지 않는 노선일 경우 예외 발생 - [ ] 삭제할 구간의 역 입력 - [ ] 구간에 존재하지 않는 역일 경우 예외 발생 - [ ] 삭제 완료 안내 출력 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index a6669d7c5..07076f194 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -17,7 +17,8 @@ public enum OutputMessage { SECTION_MANAGEMENT_SCREEN("구간 관리 화면"), SECTION_LINE("노선을 입력하세요."), SECTION_STATION("역이름을 입력하세요."), - SECTION_INDEX("순서를 입력하세요."); + SECTION_INDEX("순서를 입력하세요."), + DELETE_SECTION_LINE("삭제할 구간의 노선을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index 3e436716f..d9b8348fe 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -41,4 +41,11 @@ public int readIndex() { outputView.printNewLine(); return index; } + + public Name readDeleteLine() { + outputView.printDeleteSectionLine(); + String name = scanner.nextLine(); + outputView.printNewLine(); + return new Name(name); + } } diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index 2970de293..a38099848 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -44,6 +44,10 @@ public void printCreateSection() { System.out.println(InformationMessage.CREATE_SECTION); } + public void printDeleteSectionLine() { + System.out.println(OutputMessage.DELETE_SECTION_LINE); + } + public void printNewLine() { System.out.println(); } From 36b853645e2c4fbb8d738613162901567e6dd7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 14:41:49 +0900 Subject: [PATCH 53/70] =?UTF-8?q?feat(InputView):=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=A0=20=EA=B5=AC=EA=B0=84=EC=9D=98=20=EC=97=AD=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/view/section/SectionInputView.java | 7 +++++++ src/main/java/subway/view/section/SectionOutputView.java | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 34ae71444..fe001d3d4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -78,7 +78,7 @@ - [x] 삭제할 노선 입력 - [x] 존재하지 않는 노선일 경우 예외 발생 -- [ ] 삭제할 구간의 역 입력 +- [x] 삭제할 구간의 역 입력 - [ ] 구간에 존재하지 않는 역일 경우 예외 발생 - [ ] 삭제 완료 안내 출력 diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 07076f194..7e1221106 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -18,7 +18,8 @@ public enum OutputMessage { SECTION_LINE("노선을 입력하세요."), SECTION_STATION("역이름을 입력하세요."), SECTION_INDEX("순서를 입력하세요."), - DELETE_SECTION_LINE("삭제할 구간의 노선을 입력하세요."); + DELETE_SECTION_LINE("삭제할 구간의 노선을 입력하세요."), + DELETE_SECTION_STATION("삭제할 구간의 역을 입력하세요."); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index d9b8348fe..a4ebb0900 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -48,4 +48,11 @@ public Name readDeleteLine() { outputView.printNewLine(); return new Name(name); } + + public Name readDeleteStation() { + outputView.printDeleteSectionStation(); + String name = scanner.nextLine(); + outputView.printNewLine(); + return new Name(name); + } } diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index a38099848..067e94615 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -48,6 +48,10 @@ public void printDeleteSectionLine() { System.out.println(OutputMessage.DELETE_SECTION_LINE); } + public void printDeleteSectionStation() { + System.out.println(OutputMessage.DELETE_LINE); + } + public void printNewLine() { System.out.println(); } From b85d03548764a960d6ce335f975d2e1be267d9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 14:50:43 +0900 Subject: [PATCH 54/70] =?UTF-8?q?feat(LineRepository):=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 1 + src/main/java/subway/line/Line.java | 4 ++++ src/main/java/subway/line/LineRepository.java | 5 +++++ src/main/java/subway/line/StopStations.java | 6 +++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index fe001d3d4..d10f4d199 100644 --- a/docs/README.md +++ b/docs/README.md @@ -80,6 +80,7 @@ - [x] 존재하지 않는 노선일 경우 예외 발생 - [x] 삭제할 구간의 역 입력 - [ ] 구간에 존재하지 않는 역일 경우 예외 발생 +- [x] 구간 삭제 - [ ] 삭제 완료 안내 출력 ### 지하철 노선도 출력 diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index 456f4df93..a1a025149 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -22,6 +22,10 @@ public void addStopStation(Station station, int index) { stopStations.addStation(station, index); } + public void deleteStopStation(Station station) { + stopStations.deleteStation(station); + } + @Override public String toString() { return String.format(InformationMessage.READ_ELEMENT.toString(), name); diff --git a/src/main/java/subway/line/LineRepository.java b/src/main/java/subway/line/LineRepository.java index 65aa6434c..89f6ecdbc 100644 --- a/src/main/java/subway/line/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -41,6 +41,11 @@ public static void addStopStation(Name lineName, Station station, int index) { line.addStopStation(station, index); } + public static void deleteStopStation(Name lineName, Station station) { + Line line = findLineByName(lineName); + line.deleteStopStation(station); + } + private static Line findLineByName(Name name) { return lines.stream() .filter(line -> line.isSame(name)) diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index abc3426e8..43b2e92e0 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -31,7 +31,7 @@ public void addStation(Station station, int index) { element.add(index - START_INDEX, station); } - public void validateStation(Station station , int index) { + private void validateStation(Station station , int index) { validateExistingStation(station); validateRange(index); } @@ -47,4 +47,8 @@ private void validateRange(int index) { throw new IllegalArgumentException(ExceptionMessage.OUT_OF_RANGE.toString()); } } + + public void deleteStation(Station station) { + element.remove(station); + } } From fd2018ec2884b395cafd252503ccb481debbc880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 15:05:20 +0900 Subject: [PATCH 55/70] =?UTF-8?q?feat(OutputView):=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=20=EC=95=88=EB=82=B4=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/InformationMessage.java | 3 ++- src/main/java/subway/view/section/SectionOutputView.java | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index d10f4d199..74ee736e1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -81,7 +81,7 @@ - [x] 삭제할 구간의 역 입력 - [ ] 구간에 존재하지 않는 역일 경우 예외 발생 - [x] 구간 삭제 -- [ ] 삭제 완료 안내 출력 +- [x] 삭제 완료 안내 출력 ### 지하철 노선도 출력 diff --git a/src/main/java/subway/constant/InformationMessage.java b/src/main/java/subway/constant/InformationMessage.java index ec96ededc..18249489a 100644 --- a/src/main/java/subway/constant/InformationMessage.java +++ b/src/main/java/subway/constant/InformationMessage.java @@ -7,7 +7,8 @@ public enum InformationMessage { READ_ELEMENT("%s\n"), CREATE_LINE("지하철 노선이 등록되었습니다."), DELETE_LINE("지하철 노선이 삭제되었습니다."), - CREATE_SECTION("구간이 등록되었습니다."); + CREATE_SECTION("구간이 등록되었습니다."), + DELETE_SECTION("구간이 삭제되었습니다."); private static final String PREFIX = "[INFO] "; private final String message; diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index 067e94615..c5b8a8119 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -52,6 +52,10 @@ public void printDeleteSectionStation() { System.out.println(OutputMessage.DELETE_LINE); } + public void printDeleteSection() { + System.out.println(InformationMessage.DELETE_SECTION); + } + public void printNewLine() { System.out.println(); } From 0300a69e3cfd042da0625056712a27af74d45eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 15:14:58 +0900 Subject: [PATCH 56/70] =?UTF-8?q?feat(StopStations):=20=EA=B5=AC=EA=B0=84?= =?UTF-8?q?=EC=97=90=20=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EC=97=AD=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/line/StopStations.java | 13 ++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index 74ee736e1..e205b2265 100644 --- a/docs/README.md +++ b/docs/README.md @@ -79,7 +79,7 @@ - [x] 삭제할 노선 입력 - [x] 존재하지 않는 노선일 경우 예외 발생 - [x] 삭제할 구간의 역 입력 - - [ ] 구간에 존재하지 않는 역일 경우 예외 발생 + - [x] 구간에 존재하지 않는 역일 경우 예외 발생 - [x] 구간 삭제 - [x] 삭제 완료 안내 출력 diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index 37406b46f..04086bd3d 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -9,7 +9,8 @@ public enum ExceptionMessage { DUPLICATE_LAST_STATION("상행 종점 역과 하행 종점역인 다른 역으로 입력되어야 합니다."), DUPLICATE_LINE("이미 존재하는 노선입니다."), NOT_EXISTENT_LINE("존재하지 않는 노선입니다."), - EXISTING_SECTION("해당 노선에 이미 존재하는 역입니다."), + DUPLICATE_SECTION_STATION("해당 노선에 이미 존재하는 역입니다."), + NOT_EXISTING_STATION("해당 노선에 입력하신 역이 존재하지 않습니다."), OUT_OF_RANGE("해당 순서에 역을 추가할 수 없습니다."); private final String message; diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index 43b2e92e0..8f85dd0b0 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -32,13 +32,13 @@ public void addStation(Station station, int index) { } private void validateStation(Station station , int index) { - validateExistingStation(station); + validateDuplicateStation(station); validateRange(index); } - private void validateExistingStation(Station station) { + private void validateDuplicateStation(Station station) { if (element.contains(station)) { - throw new IllegalArgumentException(ExceptionMessage.EXISTING_SECTION.toString()); + throw new IllegalArgumentException(ExceptionMessage.DUPLICATE_SECTION_STATION.toString()); } } @@ -49,6 +49,13 @@ private void validateRange(int index) { } public void deleteStation(Station station) { + validateExistingStation(station); element.remove(station); } + + private void validateExistingStation(Station station) { + if (!element.contains(station)) { + throw new IllegalArgumentException(ExceptionMessage.NOT_EXISTING_STATION.toString()); + } + } } From 8958f79d3d67e8a29eaef02ca2800135d267004f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 15:15:48 +0900 Subject: [PATCH 57/70] =?UTF-8?q?feat(SectionController):=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=9A=94=EC=B2=AD=20=EC=B2=98=EB=A6=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/section/SectionController.java | 10 ++++++++++ src/main/java/subway/section/SectionService.java | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java index 39b92287e..8693b9727 100644 --- a/src/main/java/subway/section/SectionController.java +++ b/src/main/java/subway/section/SectionController.java @@ -22,6 +22,7 @@ public void start() { outputView.printSectionOption(); SectionOption option = inputView.readOption(); createSection(option); + deleteSection(option); } private void createSection(SectionOption option) { @@ -33,4 +34,13 @@ private void createSection(SectionOption option) { outputView.printCreateSection(); } } + + private void deleteSection(SectionOption option) { + if (option.isDelete()) { + Name lineName = inputView.readDeleteLine(); + Name stationName = inputView.readDeleteStation(); + sectionService.delete(lineName, stationName); + outputView.printDeleteSection(); + } + } } diff --git a/src/main/java/subway/section/SectionService.java b/src/main/java/subway/section/SectionService.java index cdd7b3788..8359b26bc 100644 --- a/src/main/java/subway/section/SectionService.java +++ b/src/main/java/subway/section/SectionService.java @@ -9,4 +9,8 @@ public class SectionService { public void create(Name lineName, Name stationName, int index) { LineRepository.addStopStation(lineName, StationRepository.findByName(stationName), index); } + + public void delete(Name lineName, Name stationName) { + LineRepository.deleteStopStation(lineName, StationRepository.findByName(stationName)); + } } \ No newline at end of file From d8a8f2579f6568b956970cc4978c8a450829093c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 15:27:34 +0900 Subject: [PATCH 58/70] =?UTF-8?q?feat:=20=EB=8F=8C=EC=95=84=EA=B0=80?= =?UTF-8?q?=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/line/LineController.java | 15 ++++++++++----- src/main/java/subway/line/LineOption.java | 4 ++++ src/main/java/subway/main/MainOption.java | 4 ++++ src/main/java/subway/main/SubwayController.java | 11 ++++++++--- .../java/subway/section/SectionController.java | 13 +++++++++---- src/main/java/subway/section/SectionOption.java | 4 ++++ .../java/subway/station/StationController.java | 16 +++++++++++----- src/main/java/subway/station/StationOption.java | 6 +++++- 8 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 23c24c842..af38ec20b 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -20,11 +20,16 @@ public LineController(Scanner scanner) { } public void start() { - outputView.printLineOption(); - LineOption option = inputView.readOption(); - createLine(option); - deleteLine(option); - printLines(option); + while (true) { + outputView.printLineOption(); + LineOption option = inputView.readOption(); + if (option.isBack()) { + break; + } + createLine(option); + deleteLine(option); + printLines(option); + } } public void createLine(LineOption option) { diff --git a/src/main/java/subway/line/LineOption.java b/src/main/java/subway/line/LineOption.java index 7ce2e792f..adfa1753f 100644 --- a/src/main/java/subway/line/LineOption.java +++ b/src/main/java/subway/line/LineOption.java @@ -38,6 +38,10 @@ public boolean isRead() { return this == READ; } + public boolean isBack() { + return this == BACK; + } + public String getOption() { return option; } diff --git a/src/main/java/subway/main/MainOption.java b/src/main/java/subway/main/MainOption.java index 064cdc755..d0fc75bcb 100644 --- a/src/main/java/subway/main/MainOption.java +++ b/src/main/java/subway/main/MainOption.java @@ -39,6 +39,10 @@ public boolean isSectionManagement() { return this == MainOption.SECTION_MANAGEMENT; } + public boolean isQuit() { + return this == MainOption.QUIT; + } + public String getOption() { return option; } diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java index a515e272e..3170b0043 100644 --- a/src/main/java/subway/main/SubwayController.java +++ b/src/main/java/subway/main/SubwayController.java @@ -26,9 +26,14 @@ public SubwayController(Scanner scanner) { public void start() { Initialization.init(); - outputView.printMainOptions(); - MainOption option = inputView.readOption(); - link(option); + while (true) { + outputView.printMainOptions(); + MainOption option = inputView.readOption(); + if (option.isQuit()) { + break; + } + link(option); + } } private void link(MainOption option) { diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java index 8693b9727..b6519a689 100644 --- a/src/main/java/subway/section/SectionController.java +++ b/src/main/java/subway/section/SectionController.java @@ -19,10 +19,15 @@ public SectionController(Scanner scanner) { } public void start() { - outputView.printSectionOption(); - SectionOption option = inputView.readOption(); - createSection(option); - deleteSection(option); + while (true) { + outputView.printSectionOption(); + SectionOption option = inputView.readOption(); + if (option.isBack()) { + break; + } + createSection(option); + deleteSection(option); + } } private void createSection(SectionOption option) { diff --git a/src/main/java/subway/section/SectionOption.java b/src/main/java/subway/section/SectionOption.java index 3747612b6..4533894bf 100644 --- a/src/main/java/subway/section/SectionOption.java +++ b/src/main/java/subway/section/SectionOption.java @@ -34,6 +34,10 @@ public boolean isDelete() { return this == DELETE; } + public boolean isBack() { + return this == BACK; + } + public String getOption() { return option; } diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index a17873cb8..8186254fb 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -16,11 +16,17 @@ public StationController(OutputView outputView, InputView inputView) { } public void start() { - outputView.printStationOption(); - StationOption option = inputView.readStationOption(); - createStation(option); - deleteStation(option); - printStation(option); + while (true) { + outputView.printStationOption(); + StationOption option = inputView.readStationOption(); + if (option.isBack()) { + break; + } + createStation(option); + deleteStation(option); + printStation(option); + } + } private void createStation(StationOption option) { diff --git a/src/main/java/subway/station/StationOption.java b/src/main/java/subway/station/StationOption.java index ab308668f..3f6694e42 100644 --- a/src/main/java/subway/station/StationOption.java +++ b/src/main/java/subway/station/StationOption.java @@ -36,7 +36,11 @@ public boolean isDelete() { } public boolean isRead() { - return this == READ; + return this == READ; + } + + public boolean isBack() { + return this == BACK; } public String getOption() { From 3a3773e7f3cf6f18f1fe5fad18a7de8d0ddf6e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 15:34:14 +0900 Subject: [PATCH 59/70] =?UTF-8?q?feat(SubwayController):=20=EC=A7=80?= =?UTF-8?q?=ED=95=98=EC=B2=A0=20=EB=85=B8=EC=84=A0=EB=8F=84=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/main/MainOption.java | 10 +++++++--- src/main/java/subway/main/SubwayController.java | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/subway/main/MainOption.java b/src/main/java/subway/main/MainOption.java index d0fc75bcb..112fafa02 100644 --- a/src/main/java/subway/main/MainOption.java +++ b/src/main/java/subway/main/MainOption.java @@ -28,15 +28,19 @@ public static MainOption getMainOption(String option) { } public boolean isStationManagement() { - return this == MainOption.STATION_MANAGEMENT; + return this == STATION_MANAGEMENT; } public boolean isLineManagement() { - return this == MainOption.LINE_MANAGEMENT; + return this == LINE_MANAGEMENT; } public boolean isSectionManagement() { - return this == MainOption.SECTION_MANAGEMENT; + return this == SECTION_MANAGEMENT; + } + + public boolean isSubwayMap() { + return this == SUBWAY_MAP; } public boolean isQuit() { diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java index 3170b0043..e689713b1 100644 --- a/src/main/java/subway/main/SubwayController.java +++ b/src/main/java/subway/main/SubwayController.java @@ -3,6 +3,7 @@ import subway.line.LineController; import subway.section.SectionController; import subway.station.StationController; +import subway.subwaymap.SubwayMapController; import subway.view.InputView; import subway.view.OutputView; @@ -15,6 +16,7 @@ public class SubwayController { private final StationController stationController; private final LineController lineController; private final SectionController sectionController; + private final SubwayMapController subwayMapController; public SubwayController(Scanner scanner) { this.outputView = new OutputView(); @@ -22,6 +24,7 @@ public SubwayController(Scanner scanner) { this.stationController = new StationController(outputView, inputView); this.lineController = new LineController(scanner); this.sectionController = new SectionController(scanner); + this.subwayMapController = new SubwayMapController(); } public void start() { @@ -40,6 +43,7 @@ private void link(MainOption option) { linkToStationManagement(option); linkToLineManagement(option); linkToSectionManagement(option); + linkToSubwayMap(option); } private void linkToStationManagement(MainOption option) { @@ -59,4 +63,10 @@ private void linkToSectionManagement(MainOption option) { sectionController.start(); } } + + private void linkToSubwayMap(MainOption option) { + if (option.isSubwayMap()) { + subwayMapController.start(); + } + } } From e9d1787a751266c48562da97dbacdf4301ea3523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Mon, 4 Sep 2023 15:46:47 +0900 Subject: [PATCH 60/70] =?UTF-8?q?feat:=20=EC=A7=80=ED=95=98=EC=B2=A0=20?= =?UTF-8?q?=EB=85=B8=EC=84=A0=EB=8F=84=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/constant/OutputMessage.java | 3 ++- src/main/java/subway/constant/PrintElement.java | 3 ++- src/main/java/subway/line/Line.java | 8 ++++++++ src/main/java/subway/line/StopStations.java | 7 +++++++ .../java/subway/subwaymap/SubwayMapController.java | 12 ++++++++++++ .../subway/view/subwaymap/SubwayMapOutputView.java | 14 ++++++++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/main/java/subway/subwaymap/SubwayMapController.java create mode 100644 src/main/java/subway/view/subwaymap/SubwayMapOutputView.java diff --git a/src/main/java/subway/constant/OutputMessage.java b/src/main/java/subway/constant/OutputMessage.java index 7e1221106..441418f79 100644 --- a/src/main/java/subway/constant/OutputMessage.java +++ b/src/main/java/subway/constant/OutputMessage.java @@ -19,7 +19,8 @@ public enum OutputMessage { SECTION_STATION("역이름을 입력하세요."), SECTION_INDEX("순서를 입력하세요."), DELETE_SECTION_LINE("삭제할 구간의 노선을 입력하세요."), - DELETE_SECTION_STATION("삭제할 구간의 역을 입력하세요."); + DELETE_SECTION_STATION("삭제할 구간의 역을 입력하세요."), + SUBWAY_MAP("지하철 노선도"); private static final String PREFIX = "## "; private final String message; diff --git a/src/main/java/subway/constant/PrintElement.java b/src/main/java/subway/constant/PrintElement.java index 07572cb7d..3ea351079 100644 --- a/src/main/java/subway/constant/PrintElement.java +++ b/src/main/java/subway/constant/PrintElement.java @@ -3,7 +3,8 @@ public enum PrintElement { COMMA(". "), - NEW_LINE("\n"); + NEW_LINE("\n"), + DOTTED_LINE("---"); private final String element; diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index a1a025149..5fc9fb287 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -1,6 +1,7 @@ package subway.line; import subway.constant.InformationMessage; +import subway.constant.PrintElement; import subway.station.Name; import subway.station.Station; @@ -30,4 +31,11 @@ public void deleteStopStation(Station station) { public String toString() { return String.format(InformationMessage.READ_ELEMENT.toString(), name); } + + public String getSubwayMap() { + return String.valueOf(this) + + PrintElement.DOTTED_LINE + + PrintElement.NEW_LINE + + stopStations; + } } diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index 8f85dd0b0..c2d25980e 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -58,4 +58,11 @@ private void validateExistingStation(Station station) { throw new IllegalArgumentException(ExceptionMessage.NOT_EXISTING_STATION.toString()); } } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + element.forEach(stringBuilder::append); + return stringBuilder.toString(); + } } diff --git a/src/main/java/subway/subwaymap/SubwayMapController.java b/src/main/java/subway/subwaymap/SubwayMapController.java new file mode 100644 index 000000000..11198d009 --- /dev/null +++ b/src/main/java/subway/subwaymap/SubwayMapController.java @@ -0,0 +1,12 @@ +package subway.subwaymap; + +import subway.view.subwaymap.SubwayMapOutputView; + +public class SubwayMapController { + + private final SubwayMapOutputView outputView = new SubwayMapOutputView(); + + public void start() { + outputView.printSubwayMap(); + } +} diff --git a/src/main/java/subway/view/subwaymap/SubwayMapOutputView.java b/src/main/java/subway/view/subwaymap/SubwayMapOutputView.java new file mode 100644 index 000000000..1c65e87be --- /dev/null +++ b/src/main/java/subway/view/subwaymap/SubwayMapOutputView.java @@ -0,0 +1,14 @@ +package subway.view.subwaymap; + +import subway.constant.OutputMessage; +import subway.line.LineRepository; + +public class SubwayMapOutputView { + + public void printSubwayMap() { + System.out.println(OutputMessage.SUBWAY_MAP); + System.out.println(); + LineRepository.lines() + .forEach(line -> System.out.println(line.getSubwayMap())); + } +} From 9a7de5675914e4b1db39f330b787f5ccf8acd7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 00:39:36 +0900 Subject: [PATCH 61/70] =?UTF-8?q?refactor:=20InputView,=20OutputView=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/line/LineController.java | 53 +++++++++++++--- .../java/subway/main/SubwayController.java | 13 +++- .../subway/section/SectionController.java | 56 ++++++++++++++--- .../subway/station/StationController.java | 46 ++++++++++---- src/main/java/subway/view/InputView.java | 29 +-------- .../subway/view/LineView/LineInputView.java | 53 ---------------- src/main/java/subway/view/OutputView.java | 45 -------------- .../java/subway/view/line/LineInputView.java | 37 +++++++++++ .../{LineView => line}/LineOutputView.java | 2 +- .../subway/view/section/SectionInputView.java | 31 ++-------- .../subway/view/station/StationInputView.java | 27 ++++++++ .../view/station/StationOutputView.java | 62 +++++++++++++++++++ 12 files changed, 272 insertions(+), 182 deletions(-) delete mode 100644 src/main/java/subway/view/LineView/LineInputView.java create mode 100644 src/main/java/subway/view/line/LineInputView.java rename src/main/java/subway/view/{LineView => line}/LineOutputView.java (98%) create mode 100644 src/main/java/subway/view/station/StationInputView.java create mode 100644 src/main/java/subway/view/station/StationOutputView.java diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index af38ec20b..5784f01c9 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -2,8 +2,8 @@ import subway.station.Name; import subway.station.Station; -import subway.view.LineView.LineInputView; -import subway.view.LineView.LineOutputView; +import subway.view.line.LineInputView; +import subway.view.line.LineOutputView; import java.util.Scanner; @@ -21,8 +21,7 @@ public LineController(Scanner scanner) { public void start() { while (true) { - outputView.printLineOption(); - LineOption option = inputView.readOption(); + LineOption option = readOption(); if (option.isBack()) { break; } @@ -32,23 +31,61 @@ public void start() { } } + private LineOption readOption() { + outputView.printLineOption(); + outputView.printOptions(); + LineOption option = inputView.readOption(); + outputView.printNewLine(); + return option; + } + public void createLine(LineOption option) { if (option.isCreate()) { - Name name = inputView.readLineName(); - Station upBoundStation = inputView.readUpBoundStation(); - Station descendingStation = inputView.readDescendingStation(); + Name name = readName(); + Station upBoundStation = readUpBoundStation(); + Station descendingStation = readDescendingStation(); lineService.create(name, upBoundStation, descendingStation); outputView.printCreateLine(); + outputView.printNewLine(); } } + private Name readName() { + outputView.printReadLineName(); + Name name = inputView.readLineName(); + outputView.printNewLine(); + return name; + } + + private Station readUpBoundStation() { + outputView.printUpBoundStation(); + Station station = inputView.readUpBoundStation(); + outputView.printNewLine(); + return station; + } + + private Station readDescendingStation() { + outputView.printDescendingStation(); + Station station = inputView.readDescendingStation(); + outputView.printNewLine(); + return station; + } + public void deleteLine(LineOption option) { if (option.isDelete()) { - lineService.delete(inputView.readDeleteStation()); + lineService.delete(readDeleteStation()); outputView.printDeleteLine(); + outputView.printNewLine(); } } + private Name readDeleteStation() { + outputView.printReadDeleteLine(); + Name name = inputView.readDeleteStation(); + outputView.printNewLine(); + return name; + } + public void printLines(LineOption option) { if (option.isRead()) { outputView.printLines(); diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java index e689713b1..4bdbbb6f7 100644 --- a/src/main/java/subway/main/SubwayController.java +++ b/src/main/java/subway/main/SubwayController.java @@ -21,7 +21,7 @@ public class SubwayController { public SubwayController(Scanner scanner) { this.outputView = new OutputView(); this.inputView = new InputView(scanner); - this.stationController = new StationController(outputView, inputView); + this.stationController = new StationController(scanner); this.lineController = new LineController(scanner); this.sectionController = new SectionController(scanner); this.subwayMapController = new SubwayMapController(); @@ -30,8 +30,7 @@ public SubwayController(Scanner scanner) { public void start() { Initialization.init(); while (true) { - outputView.printMainOptions(); - MainOption option = inputView.readOption(); + MainOption option = readOption(); if (option.isQuit()) { break; } @@ -39,6 +38,14 @@ public void start() { } } + private MainOption readOption() { + outputView.printMainOptions(); + outputView.printOptions(); + MainOption option = inputView.readOption(); + outputView.printNewLine(); + return option; + } + private void link(MainOption option) { linkToStationManagement(option); linkToLineManagement(option); diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java index b6519a689..d8e2d795e 100644 --- a/src/main/java/subway/section/SectionController.java +++ b/src/main/java/subway/section/SectionController.java @@ -20,8 +20,7 @@ public SectionController(Scanner scanner) { public void start() { while (true) { - outputView.printSectionOption(); - SectionOption option = inputView.readOption(); + SectionOption option = readOption(); if (option.isBack()) { break; } @@ -30,22 +29,63 @@ public void start() { } } + private SectionOption readOption() { + outputView.printSectionOption(); + outputView.printOptions(); + SectionOption option = inputView.readOption(); + outputView.printNewLine(); + return option; + } + private void createSection(SectionOption option) { if (option.isCreate()) { - Name lineName = inputView.readLineName(); - Name stationName = inputView.readStationName(); - int index = inputView.readIndex(); + Name lineName = readLineName(); + Name stationName = readStationName(); + int index = readIndex(); sectionService.create(lineName, stationName, index); outputView.printCreateSection(); } } + private Name readLineName() { + outputView.printReadLineName(); + Name name = inputView.readLineName(); + outputView.printNewLine(); + return name; + } + + private Name readStationName() { + outputView.printReadStationName(); + Name name = inputView.readStationName(); + outputView.printNewLine(); + return name; + } + + private int readIndex() { + outputView.printReadIndex(); + int index = inputView.readIndex(); + outputView.printNewLine(); + return index; + } + private void deleteSection(SectionOption option) { if (option.isDelete()) { - Name lineName = inputView.readDeleteLine(); - Name stationName = inputView.readDeleteStation(); - sectionService.delete(lineName, stationName); + sectionService.delete(readDeleteLine(), readDeleteStation()); outputView.printDeleteSection(); } } + + public Name readDeleteLine() { + outputView.printDeleteSectionLine(); + Name name = inputView.readDeleteLine(); + outputView.printNewLine(); + return name; + } + + public Name readDeleteStation() { + outputView.printDeleteSectionStation(); + Name name = inputView.readDeleteStation(); + outputView.printNewLine(); + return name; + } } diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index 8186254fb..aca13309c 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -1,24 +1,25 @@ package subway.station; -import subway.view.InputView; -import subway.view.OutputView; +import subway.view.station.StationInputView; +import subway.view.station.StationOutputView; + +import java.util.Scanner; public class StationController { - private final OutputView outputView; - private final InputView inputView; + private final StationOutputView outputView; + private final StationInputView inputView; private final StationService stationService; - public StationController(OutputView outputView, InputView inputView) { - this.outputView = outputView; - this.inputView = inputView; + public StationController(Scanner scanner) { + this.outputView = new StationOutputView(); + this.inputView = new StationInputView(scanner); this.stationService = new StationService(); } public void start() { while (true) { - outputView.printStationOption(); - StationOption option = inputView.readStationOption(); + StationOption option = readStationOption(); if (option.isBack()) { break; } @@ -26,23 +27,46 @@ public void start() { deleteStation(option); printStation(option); } + } + private StationOption readStationOption() { + outputView.printStationOption(); + outputView.printOptions(); + StationOption option = inputView.readStationOption(); + outputView.printNewLine(); + return option; } private void createStation(StationOption option) { if (option.isCreate()) { - stationService.create(inputView.readStationName()); + stationService.create(readStationName()); outputView.printCreated(); + outputView.printNewLine(); } } + private Name readStationName() { + outputView.printStationCreation(); + Name name = inputView.readStationName(); + outputView.printNewLine(); + return name; + } + private void deleteStation(StationOption option) { if (option.isDelete()) { - stationService.delete(inputView.readDeleteStationName()); + stationService.delete(readDeleteStationName()); outputView.printDeleted(); + outputView.printNewLine(); } } + private Name readDeleteStationName() { + outputView.printDeleteStation(); + Name name = inputView.readDeleteStationName(); + outputView.printNewLine(); + return name; + } + private void printStation(StationOption option) { if (option.isRead()) { outputView.printStations(); diff --git a/src/main/java/subway/view/InputView.java b/src/main/java/subway/view/InputView.java index c0f7e6b1c..e3b576f2c 100644 --- a/src/main/java/subway/view/InputView.java +++ b/src/main/java/subway/view/InputView.java @@ -1,45 +1,18 @@ package subway.view; import subway.main.MainOption; -import subway.station.Name; -import subway.station.StationOption; import java.util.Scanner; public class InputView { private final Scanner scanner; - private final OutputView outputView = new OutputView(); public InputView(Scanner scanner) { this.scanner = scanner; } public MainOption readOption() { - outputView.printOptions(); - MainOption option = MainOption.getMainOption(scanner.nextLine()); - outputView.printNewLine(); - return option; - } - - public StationOption readStationOption() { - outputView.printOptions(); - StationOption option = StationOption.getStationOption(scanner.nextLine()); - outputView.printNewLine(); - return option; - } - - public Name readStationName() { - outputView.printStationCreation(); - String name = scanner.nextLine(); - outputView.printNewLine(); - return new Name(name); - } - - public Name readDeleteStationName() { - outputView.printDeleteStation(); - String name = scanner.nextLine(); - outputView.printNewLine(); - return new Name(name); + return MainOption.getMainOption(scanner.nextLine()); } } diff --git a/src/main/java/subway/view/LineView/LineInputView.java b/src/main/java/subway/view/LineView/LineInputView.java deleted file mode 100644 index 57fce2b78..000000000 --- a/src/main/java/subway/view/LineView/LineInputView.java +++ /dev/null @@ -1,53 +0,0 @@ -package subway.view.LineView; - -import subway.line.LineOption; -import subway.station.Name; -import subway.station.Station; -import subway.station.StationRepository; - -import java.util.Scanner; - -public class LineInputView { - - private final Scanner scanner; - private final LineOutputView outputView = new LineOutputView(); - - public LineInputView(Scanner scanner) { - this.scanner = scanner; - } - - public LineOption readOption() { - outputView.printOptions(); - LineOption option = LineOption.getOption(scanner.nextLine()); - outputView.printNewLine(); - return option; - } - - public Name readLineName() { - outputView.printReadLineName(); - String name = scanner.nextLine(); - outputView.printNewLine(); - return new Name(name); - } - - public Station readUpBoundStation() { - outputView.printUpBoundStation(); - Station station = StationRepository.findByName(new Name(scanner.nextLine())); - outputView.printNewLine(); - return station; - } - - public Station readDescendingStation() { - outputView.printDescendingStation(); - Station station = StationRepository.findByName(new Name(scanner.nextLine())); - outputView.printNewLine(); - return station; - } - - public Name readDeleteStation() { - outputView.printReadDeleteLine(); - Name name = new Name(scanner.nextLine()); - outputView.printNewLine(); - return name; - } -} diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index ea264179f..151e4afc4 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -1,12 +1,8 @@ package subway.view; -import subway.constant.InformationMessage; import subway.constant.OutputMessage; import subway.constant.PrintElement; import subway.main.MainOption; -import subway.station.Station; -import subway.station.StationOption; -import subway.station.StationRepository; import java.util.Arrays; @@ -29,47 +25,6 @@ public void printOptions() { System.out.println(OutputMessage.OPTION_SELECT); } - public void printStationOption() { - StringBuilder stringBuilder = new StringBuilder(); - Arrays.stream(StationOption.values()) - .forEach(value -> - stringBuilder.append(value.getOption()) - .append(PrintElement.COMMA) - .append(value.getTitle()) - .append(PrintElement.NEW_LINE) - ); - System.out.println(OutputMessage.STATION_OPTION_SELECT); - System.out.println(stringBuilder); - } - - public void printStationCreation() { - System.out.println(OutputMessage.CREATE_STATION); - } - - public void printCreated() { - System.out.println(InformationMessage.COMPLETE_CREATE_STATION); - } - - public void printDeleteStation() { - System.out.println(OutputMessage.DELETE_STATION); - } - - public void printDeleted() { - System.out.println(InformationMessage.COMPLETE_DELETE_STATION); - } - - public void printStations() { - StringBuilder stringBuilder = new StringBuilder(); - StationRepository.stations() - .forEach(station -> appendStations(stringBuilder, station)); - System.out.println(OutputMessage.READ_STATION); - System.out.println(stringBuilder); - } - - private void appendStations(StringBuilder stringBuilder, Station station) { - stringBuilder.append(station); - } - public void printNewLine() { System.out.println(); } diff --git a/src/main/java/subway/view/line/LineInputView.java b/src/main/java/subway/view/line/LineInputView.java new file mode 100644 index 000000000..588b6f8af --- /dev/null +++ b/src/main/java/subway/view/line/LineInputView.java @@ -0,0 +1,37 @@ +package subway.view.line; + +import subway.line.LineOption; +import subway.station.Name; +import subway.station.Station; +import subway.station.StationRepository; + +import java.util.Scanner; + +public class LineInputView { + + private final Scanner scanner; + + public LineInputView(Scanner scanner) { + this.scanner = scanner; + } + + public LineOption readOption() { + return LineOption.getOption(scanner.nextLine()); + } + + public Name readLineName() { + return new Name(scanner.nextLine()); + } + + public Station readUpBoundStation() { + return StationRepository.findByName(new Name(scanner.nextLine())); + } + + public Station readDescendingStation() { + return StationRepository.findByName(new Name(scanner.nextLine())); + } + + public Name readDeleteStation() { + return new Name(scanner.nextLine()); + } +} diff --git a/src/main/java/subway/view/LineView/LineOutputView.java b/src/main/java/subway/view/line/LineOutputView.java similarity index 98% rename from src/main/java/subway/view/LineView/LineOutputView.java rename to src/main/java/subway/view/line/LineOutputView.java index f62b910d0..304b7aa5a 100644 --- a/src/main/java/subway/view/LineView/LineOutputView.java +++ b/src/main/java/subway/view/line/LineOutputView.java @@ -1,4 +1,4 @@ -package subway.view.LineView; +package subway.view.line; import subway.constant.InformationMessage; import subway.constant.OutputMessage; diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index a4ebb0900..8cbff7c16 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -8,51 +8,32 @@ public class SectionInputView { private final Scanner scanner; - private final SectionOutputView outputView = new SectionOutputView(); public SectionInputView(Scanner scanner) { this.scanner = scanner; } public SectionOption readOption() { - outputView.printOptions(); - SectionOption option = SectionOption.getOption(scanner.nextLine()); - outputView.printNewLine(); - return option; + return SectionOption.getOption(scanner.nextLine()); } public Name readLineName() { - outputView.printReadLineName(); - String name = scanner.nextLine(); - outputView.printNewLine(); - return new Name(name); + return new Name(scanner.nextLine()); } public Name readStationName() { - outputView.printReadStationName(); - String name = scanner.nextLine(); - outputView.printNewLine(); - return new Name(name); + return new Name(scanner.nextLine()); } public int readIndex() { - outputView.printReadIndex(); - int index = scanner.nextInt(); - outputView.printNewLine(); - return index; + return scanner.nextInt(); } public Name readDeleteLine() { - outputView.printDeleteSectionLine(); - String name = scanner.nextLine(); - outputView.printNewLine(); - return new Name(name); + return new Name(scanner.nextLine()); } public Name readDeleteStation() { - outputView.printDeleteSectionStation(); - String name = scanner.nextLine(); - outputView.printNewLine(); - return new Name(name); + return new Name(scanner.nextLine()); } } diff --git a/src/main/java/subway/view/station/StationInputView.java b/src/main/java/subway/view/station/StationInputView.java new file mode 100644 index 000000000..fb9177fa4 --- /dev/null +++ b/src/main/java/subway/view/station/StationInputView.java @@ -0,0 +1,27 @@ +package subway.view.station; + +import subway.station.Name; +import subway.station.StationOption; + +import java.util.Scanner; + +public class StationInputView { + + private final Scanner scanner; + + public StationInputView(Scanner scanner) { + this.scanner = scanner; + } + + public StationOption readStationOption() { + return StationOption.getStationOption(scanner.nextLine()); + } + + public Name readStationName() { + return new Name(scanner.nextLine()); + } + + public Name readDeleteStationName() { + return new Name(scanner.nextLine()); + } +} diff --git a/src/main/java/subway/view/station/StationOutputView.java b/src/main/java/subway/view/station/StationOutputView.java new file mode 100644 index 000000000..1c28a1b5f --- /dev/null +++ b/src/main/java/subway/view/station/StationOutputView.java @@ -0,0 +1,62 @@ +package subway.view.station; + +import subway.constant.InformationMessage; +import subway.constant.OutputMessage; +import subway.constant.PrintElement; +import subway.station.Station; +import subway.station.StationOption; +import subway.station.StationRepository; + +import java.util.Arrays; + +public class StationOutputView { + + public void printOptions() { + System.out.println(OutputMessage.OPTION_SELECT); + } + + public void printStationOption() { + StringBuilder stringBuilder = new StringBuilder(); + Arrays.stream(StationOption.values()) + .forEach(value -> + stringBuilder.append(value.getOption()) + .append(PrintElement.COMMA) + .append(value.getTitle()) + .append(PrintElement.NEW_LINE) + ); + System.out.println(OutputMessage.STATION_OPTION_SELECT); + System.out.println(stringBuilder); + } + + public void printStationCreation() { + System.out.println(OutputMessage.CREATE_STATION); + } + + public void printCreated() { + System.out.println(InformationMessage.COMPLETE_CREATE_STATION); + } + + public void printDeleteStation() { + System.out.println(OutputMessage.DELETE_STATION); + } + + public void printDeleted() { + System.out.println(InformationMessage.COMPLETE_DELETE_STATION); + } + + public void printStations() { + StringBuilder stringBuilder = new StringBuilder(); + StationRepository.stations() + .forEach(station -> appendStations(stringBuilder, station)); + System.out.println(OutputMessage.READ_STATION); + System.out.println(stringBuilder); + } + + private void appendStations(StringBuilder stringBuilder, Station station) { + stringBuilder.append(station); + } + + public void printNewLine() { + System.out.println(); + } +} From 704b1476b9b613075a6354826bfdecbc273b5985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 00:49:27 +0900 Subject: [PATCH 62/70] =?UTF-8?q?feat:=20=EC=98=88=EC=99=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=20=EC=8B=9C=20=EC=9E=AC=EC=8B=9C=EC=9E=91=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/subway/constant/ExceptionMessage.java | 3 ++- src/main/java/subway/line/LineController.java | 16 ++++++++++------ src/main/java/subway/main/SubwayController.java | 12 ++++++++---- .../java/subway/section/SectionController.java | 14 +++++++++----- .../java/subway/station/StationController.java | 16 ++++++++++------ src/main/java/subway/view/OutputView.java | 6 ++++++ .../java/subway/view/line/LineOutputView.java | 6 ++++++ .../subway/view/section/SectionOutputView.java | 6 ++++++ .../subway/view/station/StationOutputView.java | 6 ++++++ 9 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/main/java/subway/constant/ExceptionMessage.java b/src/main/java/subway/constant/ExceptionMessage.java index 04086bd3d..0919819f2 100644 --- a/src/main/java/subway/constant/ExceptionMessage.java +++ b/src/main/java/subway/constant/ExceptionMessage.java @@ -13,6 +13,7 @@ public enum ExceptionMessage { NOT_EXISTING_STATION("해당 노선에 입력하신 역이 존재하지 않습니다."), OUT_OF_RANGE("해당 순서에 역을 추가할 수 없습니다."); + private static final String PREFIX = "[ERROR] "; private final String message; ExceptionMessage(String message) { @@ -21,6 +22,6 @@ public enum ExceptionMessage { @Override public String toString() { - return message; + return PREFIX + message; } } diff --git a/src/main/java/subway/line/LineController.java b/src/main/java/subway/line/LineController.java index 5784f01c9..552acba3d 100644 --- a/src/main/java/subway/line/LineController.java +++ b/src/main/java/subway/line/LineController.java @@ -21,13 +21,17 @@ public LineController(Scanner scanner) { public void start() { while (true) { - LineOption option = readOption(); - if (option.isBack()) { - break; + try { + LineOption option = readOption(); + if (option.isBack()) { + break; + } + createLine(option); + deleteLine(option); + printLines(option); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception.getMessage()); } - createLine(option); - deleteLine(option); - printLines(option); } } diff --git a/src/main/java/subway/main/SubwayController.java b/src/main/java/subway/main/SubwayController.java index 4bdbbb6f7..5b42e1ed2 100644 --- a/src/main/java/subway/main/SubwayController.java +++ b/src/main/java/subway/main/SubwayController.java @@ -30,11 +30,15 @@ public SubwayController(Scanner scanner) { public void start() { Initialization.init(); while (true) { - MainOption option = readOption(); - if (option.isQuit()) { - break; + try { + MainOption option = readOption(); + if (option.isQuit()) { + break; + } + link(option); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception.getMessage()); } - link(option); } } diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java index d8e2d795e..cb0d05337 100644 --- a/src/main/java/subway/section/SectionController.java +++ b/src/main/java/subway/section/SectionController.java @@ -20,12 +20,16 @@ public SectionController(Scanner scanner) { public void start() { while (true) { - SectionOption option = readOption(); - if (option.isBack()) { - break; + try { + SectionOption option = readOption(); + if (option.isBack()) { + break; + } + createSection(option); + deleteSection(option); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception.getMessage()); } - createSection(option); - deleteSection(option); } } diff --git a/src/main/java/subway/station/StationController.java b/src/main/java/subway/station/StationController.java index aca13309c..b89c14d5e 100644 --- a/src/main/java/subway/station/StationController.java +++ b/src/main/java/subway/station/StationController.java @@ -19,13 +19,17 @@ public StationController(Scanner scanner) { public void start() { while (true) { - StationOption option = readStationOption(); - if (option.isBack()) { - break; + try { + StationOption option = readStationOption(); + if (option.isBack()) { + break; + } + createStation(option); + deleteStation(option); + printStation(option); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception.getMessage()); } - createStation(option); - deleteStation(option); - printStation(option); } } diff --git a/src/main/java/subway/view/OutputView.java b/src/main/java/subway/view/OutputView.java index 151e4afc4..7ddf0868b 100644 --- a/src/main/java/subway/view/OutputView.java +++ b/src/main/java/subway/view/OutputView.java @@ -28,4 +28,10 @@ public void printOptions() { public void printNewLine() { System.out.println(); } + + public void printExceptionMessage(String message) { + System.out.println(); + System.out.println(message); + System.out.println(); + } } diff --git a/src/main/java/subway/view/line/LineOutputView.java b/src/main/java/subway/view/line/LineOutputView.java index 304b7aa5a..b3b3ac250 100644 --- a/src/main/java/subway/view/line/LineOutputView.java +++ b/src/main/java/subway/view/line/LineOutputView.java @@ -67,4 +67,10 @@ public void printLines() { private void appendStations(StringBuilder stringBuilder, Line line) { stringBuilder.append(line); } + + public void printExceptionMessage(String message) { + System.out.println(); + System.out.println(message); + System.out.println(); + } } diff --git a/src/main/java/subway/view/section/SectionOutputView.java b/src/main/java/subway/view/section/SectionOutputView.java index c5b8a8119..7b7ef0bce 100644 --- a/src/main/java/subway/view/section/SectionOutputView.java +++ b/src/main/java/subway/view/section/SectionOutputView.java @@ -59,4 +59,10 @@ public void printDeleteSection() { public void printNewLine() { System.out.println(); } + + public void printExceptionMessage(String message) { + System.out.println(); + System.out.println(message); + System.out.println(); + } } diff --git a/src/main/java/subway/view/station/StationOutputView.java b/src/main/java/subway/view/station/StationOutputView.java index 1c28a1b5f..b7fe46b10 100644 --- a/src/main/java/subway/view/station/StationOutputView.java +++ b/src/main/java/subway/view/station/StationOutputView.java @@ -59,4 +59,10 @@ private void appendStations(StringBuilder stringBuilder, Station station) { public void printNewLine() { System.out.println(); } + + public void printExceptionMessage(String message) { + System.out.println(); + System.out.println(message); + System.out.println(); + } } From 4d12fd04b9474a26e216b97a2ba9b3f60b44d989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 02:23:15 +0900 Subject: [PATCH 63/70] =?UTF-8?q?test(LineOption):=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/subway/line/LineOptionTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/test/java/subway/line/LineOptionTest.java diff --git a/src/test/java/subway/line/LineOptionTest.java b/src/test/java/subway/line/LineOptionTest.java new file mode 100644 index 000000000..ad5f5fb1a --- /dev/null +++ b/src/test/java/subway/line/LineOptionTest.java @@ -0,0 +1,72 @@ +package subway.line; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class LineOptionTest { + + private static final String ERROR_MESSAGE = "[ERROR]"; + + @DisplayName("사용자가 1, 2, 3, B를 입력하면 해당하는 기능을 반환한다.") + @Test + void getLineOption() { + String input = "1"; + + LineOption option = LineOption.getOption(input); + + assertThat(option).isEqualTo(LineOption.CREATE); + } + + @DisplayName("목록에 없는 옵션을 선택할 경우 예외가 발생한다.") + @Test + void lineOptionException() { + String input = "1241"; + + assertThatThrownBy(() -> LineOption.getOption(input)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("옵션이 CREATE 상태이면 true를 반환한다.") + @Test + void getCreateOption() { + String input = "1"; + + LineOption option = LineOption.getOption(input); + + assertThat(option).isEqualTo(LineOption.CREATE); + } + + @DisplayName("옵션이 DELETE 상태이면 true를 반환한다.") + @Test + void getDeleteOption() { + String input = "2"; + + LineOption option = LineOption.getOption(input); + + assertThat(option).isEqualTo(LineOption.DELETE); + } + + @DisplayName("옵션이 Read 상태이면 true를 반환한다.") + @Test + void getReadOption() { + String input = "3"; + + LineOption option = LineOption.getOption(input); + + assertThat(option).isEqualTo(LineOption.READ); + } + + @DisplayName("옵션이 Back 상태이면 true를 반환한다.") + @Test + void getBackOption() { + String input = "B"; + + LineOption option = LineOption.getOption(input); + + assertThat(option).isEqualTo(LineOption.BACK); + } +} From fbf556489ef78a4e3751e643a6cac4720d0d6f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 02:57:13 +0900 Subject: [PATCH 64/70] =?UTF-8?q?test(LineRepository):=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EA=B4=80=EB=A6=AC=20=EC=98=88=EC=99=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/subway/line/LineRepositoryTest.java | 60 +++++++++++++++++++ src/test/java/subway/line/LineTest.java | 20 +++++++ 2 files changed, 80 insertions(+) create mode 100644 src/test/java/subway/line/LineRepositoryTest.java create mode 100644 src/test/java/subway/line/LineTest.java diff --git a/src/test/java/subway/line/LineRepositoryTest.java b/src/test/java/subway/line/LineRepositoryTest.java new file mode 100644 index 000000000..2f4fed53d --- /dev/null +++ b/src/test/java/subway/line/LineRepositoryTest.java @@ -0,0 +1,60 @@ +package subway.line; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import subway.station.Name; +import subway.station.Station; +import subway.station.StationRepository; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class LineRepositoryTest { + + private static final String ERROR_MESSAGE = "[ERROR]"; + + @BeforeAll + public static void initStations() { + StationRepository.addStation(new Name("강남역")); + StationRepository.addStation(new Name("교대역")); + } + + @DisplayName("이미 존재하는 노선을 다시 생성할 경우 예외 발생") + @Test + void validateDuplicateStation() { + Name lineName = new Name("2호선"); + Station upBoundStation = StationRepository.findByName(new Name("강남역")); + Station descendingStation = StationRepository.findByName(new Name("교대역")); + StopStations stopStations = new StopStations(List.of(upBoundStation, descendingStation)); + + LineRepository.addLine(lineName, stopStations); + + assertThatThrownBy(() -> LineRepository.addLine(lineName, stopStations)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("존재하지 않는 노선을 삭제할 경우 예외 발생") + @Test + void deleteLineException() { + Name name = new Name("14호선"); + + assertThatThrownBy(() -> LineRepository.deleteLineByName(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("존재하지 않는 노선에 구간을 추가할 경우 예외 발생") + @Test + void addStopStationException() { + Name name = new Name("14호선"); + Station station = StationRepository.findByName(new Name("강남역")); + + assertThatThrownBy(() -> LineRepository.addStopStation(name, station, 1)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } +} diff --git a/src/test/java/subway/line/LineTest.java b/src/test/java/subway/line/LineTest.java new file mode 100644 index 000000000..63804bd87 --- /dev/null +++ b/src/test/java/subway/line/LineTest.java @@ -0,0 +1,20 @@ +package subway.line; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class LineTest { + +// @DisplayName("같은 이름일 경우 true를 반환한다.") +// @Test +// void checkSameName() { +// Name name = new Name("1호선"); +// List stations = List.of(new Station(new Name("교대역")), new Station(new Name("잠실역"))); +// StopStations stopStations = new StopStations(stations); +// Line line = new Line(name, stopStations); +// +// assertThat(line.isSame(new Name("1호선"))).isTrue(); +// } +} From 4ed666968a187ae9354ed23683c12ea20ab6096a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 13:46:27 +0900 Subject: [PATCH 65/70] =?UTF-8?q?feat:=20=EC=97=AD=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EC=8B=9C=20=ED=8F=AC=ED=95=A8=EB=90=9C=20=EB=85=B8=EC=84=A0?= =?UTF-8?q?=EC=97=90=EC=84=9C=EB=8F=84=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 +++--- src/main/java/subway/line/LineRepository.java | 6 ++++++ src/main/java/subway/line/StopStations.java | 4 ++++ src/main/java/subway/station/StationRepository.java | 3 +-- src/main/java/subway/station/StationService.java | 6 +++++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index e205b2265..af1355171 100644 --- a/docs/README.md +++ b/docs/README.md @@ -22,8 +22,8 @@ **역 삭제** - [x] 삭제할 역 이름 입력 - [x] 존재하지 않는 역일 경우 예외 발생 -- [ ] 삭제 - - [ ] 노선에 등록된 역일 경우 노선에서 삭제 +- [x] 삭제 + - [x] 노선에 등록된 역일 경우 노선에서 삭제 - [x] 역 삭제 - [x] 삭제 완료 안내 출력 @@ -85,4 +85,4 @@ ### 지하철 노선도 출력 -- [ ] 지하철 노선도 출력 \ No newline at end of file +- [x] 지하철 노선도 출력 \ No newline at end of file diff --git a/src/main/java/subway/line/LineRepository.java b/src/main/java/subway/line/LineRepository.java index 89f6ecdbc..6d97b4895 100644 --- a/src/main/java/subway/line/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -31,6 +31,12 @@ private static boolean isDuplicateName(Name name) { .anyMatch(line -> line.isSame(name)); } + public static void deleteStopStation(Station station) { + lines.stream() + .filter(line -> line.isContainStation(station)) + .forEach(lines -> lines.deleteStopStation(station)); + } + public static void deleteLineByName(Name name) { Line line = findLineByName(name); lines.remove(line); diff --git a/src/main/java/subway/line/StopStations.java b/src/main/java/subway/line/StopStations.java index c2d25980e..d0299bf75 100644 --- a/src/main/java/subway/line/StopStations.java +++ b/src/main/java/subway/line/StopStations.java @@ -59,6 +59,10 @@ private void validateExistingStation(Station station) { } } + public boolean contain(Station station) { + return element.contains(station); + } + @Override public String toString() { StringBuilder stringBuilder = new StringBuilder(); diff --git a/src/main/java/subway/station/StationRepository.java b/src/main/java/subway/station/StationRepository.java index 6f2c0f0ac..494a64a57 100644 --- a/src/main/java/subway/station/StationRepository.java +++ b/src/main/java/subway/station/StationRepository.java @@ -29,8 +29,7 @@ private static boolean isDuplicateName(Name name) { .anyMatch(station -> station.isSame(name)); } - public static void deleteStation(Name name) { - Station station = findByName(name); + public static void deleteStation(Station station) { stations.remove(station); } diff --git a/src/main/java/subway/station/StationService.java b/src/main/java/subway/station/StationService.java index b0a2e4352..c0f8d95ad 100644 --- a/src/main/java/subway/station/StationService.java +++ b/src/main/java/subway/station/StationService.java @@ -1,5 +1,7 @@ package subway.station; +import subway.line.LineRepository; + public class StationService { public void create(Name name) { @@ -7,6 +9,8 @@ public void create(Name name) { } public void delete(Name name) { - StationRepository.deleteStation(name); + Station station = StationRepository.findByName(name); + LineRepository.deleteStopStation(station); + StationRepository.deleteStation(station); } } From a0fc39adadf202d7089e36570875df470fff0c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 13:47:08 +0900 Subject: [PATCH 66/70] =?UTF-8?q?test(LineOption):=20=EC=98=B5=EC=85=98=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=ED=99=95=EC=9D=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/line/Line.java | 4 ++++ src/test/java/subway/line/LineOptionTest.java | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/subway/line/Line.java b/src/main/java/subway/line/Line.java index 5fc9fb287..dea0cfead 100644 --- a/src/main/java/subway/line/Line.java +++ b/src/main/java/subway/line/Line.java @@ -27,6 +27,10 @@ public void deleteStopStation(Station station) { stopStations.deleteStation(station); } + public boolean isContainStation(Station station) { + return stopStations.contain(station); + } + @Override public String toString() { return String.format(InformationMessage.READ_ELEMENT.toString(), name); diff --git a/src/test/java/subway/line/LineOptionTest.java b/src/test/java/subway/line/LineOptionTest.java index ad5f5fb1a..99862329c 100644 --- a/src/test/java/subway/line/LineOptionTest.java +++ b/src/test/java/subway/line/LineOptionTest.java @@ -37,7 +37,7 @@ void getCreateOption() { LineOption option = LineOption.getOption(input); - assertThat(option).isEqualTo(LineOption.CREATE); + assertThat(option.isCreate()).isTrue(); } @DisplayName("옵션이 DELETE 상태이면 true를 반환한다.") @@ -47,7 +47,7 @@ void getDeleteOption() { LineOption option = LineOption.getOption(input); - assertThat(option).isEqualTo(LineOption.DELETE); + assertThat(option.isDelete()).isTrue(); } @DisplayName("옵션이 Read 상태이면 true를 반환한다.") @@ -57,7 +57,7 @@ void getReadOption() { LineOption option = LineOption.getOption(input); - assertThat(option).isEqualTo(LineOption.READ); + assertThat(option.isRead()).isTrue(); } @DisplayName("옵션이 Back 상태이면 true를 반환한다.") @@ -67,6 +67,6 @@ void getBackOption() { LineOption option = LineOption.getOption(input); - assertThat(option).isEqualTo(LineOption.BACK); + assertThat(option.isBack()).isTrue(); } } From 0cb6e0a93821c21581326704bf95e64b845b4f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 14:14:36 +0900 Subject: [PATCH 67/70] =?UTF-8?q?test(StopStation):=20=EC=A0=95=EC=B0=A8?= =?UTF-8?q?=EC=97=AD=20=EC=B6=94=EA=B0=80=20=EC=82=AD=EC=A0=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/subway/line/StopStationsTest.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/test/java/subway/line/StopStationsTest.java diff --git a/src/test/java/subway/line/StopStationsTest.java b/src/test/java/subway/line/StopStationsTest.java new file mode 100644 index 000000000..a20a086bf --- /dev/null +++ b/src/test/java/subway/line/StopStationsTest.java @@ -0,0 +1,92 @@ +package subway.line; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import subway.station.Name; +import subway.station.Station; +import subway.station.StationRepository; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class StopStationsTest { + + private static final String ERROR_MESSAGE = "[ERROR]"; + + @BeforeAll + public static void initStations() { + StationRepository.addStation(new Name("남부터미널역")); + StationRepository.addStation(new Name("양재역")); + StationRepository.addStation(new Name("매봉역")); + } + + @DisplayName("하행 종점역과 상행 종점역이 같을 경우 예외가 발생한다.") + @Test + void sameTerminalException() { + Station upBoundStation = StationRepository.findByName(new Name("양재역")); + Station descendingStation = StationRepository.findByName(new Name("양재역")); + + assertThatThrownBy(() -> new StopStations(List.of(upBoundStation, descendingStation))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("구간에 이미 존재하는 역을 추가하면 예외가 발생한다.") + @Test + void duplicateException() { + Station upBoundStation = StationRepository.findByName(new Name("양재역")); + Station descendingStation = StationRepository.findByName(new Name("매봉역")); + StopStations stopStations = new StopStations(List.of(upBoundStation, descendingStation)); + + Station duplicateStation = StationRepository.findByName(new Name("양재역")); + int index = 1; + + assertThatThrownBy(() -> stopStations.addStation(duplicateStation, index)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("범위 밖의 순서를 입력하면 예외가 발생한다.") + @Test + void rangeException() { + Station upBoundStation = StationRepository.findByName(new Name("양재역")); + Station descendingStation = StationRepository.findByName(new Name("매봉역")); + StopStations stopStations = new StopStations(List.of(upBoundStation, descendingStation)); + + Station duplicateStation = StationRepository.findByName(new Name("남부터미널역")); + int index = 100; + + assertThatThrownBy(() -> stopStations.addStation(duplicateStation, index)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("구간 삭제 시 존재하지 않는 역을 삭제하면 예외가 발생한다.") + @Test + void deleteException() { + Station upBoundStation = StationRepository.findByName(new Name("양재역")); + Station descendingStation = StationRepository.findByName(new Name("매봉역")); + StopStations stopStations = new StopStations(List.of(upBoundStation, descendingStation)); + + Station station = StationRepository.findByName(new Name("남부터미널역")); + + assertThatThrownBy(() -> stopStations.deleteStation(station)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("입력받은 역이 구간 안에 존재하는 경우 True를 반환한다.") + @Test + void containStation() { + Station upBoundStation = StationRepository.findByName(new Name("양재역")); + Station descendingStation = StationRepository.findByName(new Name("매봉역")); + StopStations stopStations = new StopStations(List.of(upBoundStation, descendingStation)); + + Station station = StationRepository.findByName(new Name("양재역")); + + assertThat(stopStations.contain(station)).isTrue(); + } +} From 56c5fc549e041dea74aa69533341c7a451e68a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 14:18:33 +0900 Subject: [PATCH 68/70] =?UTF-8?q?test(SectionOption):=20=EA=B5=AC=EA=B0=84?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B4=80=EB=A6=AC=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subway/section/SectionOptionTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/test/java/subway/section/SectionOptionTest.java diff --git a/src/test/java/subway/section/SectionOptionTest.java b/src/test/java/subway/section/SectionOptionTest.java new file mode 100644 index 000000000..12e72b214 --- /dev/null +++ b/src/test/java/subway/section/SectionOptionTest.java @@ -0,0 +1,62 @@ +package subway.section; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class SectionOptionTest { + + private static final String ERROR_MESSAGE = "[ERROR]"; + + @DisplayName("사용자가 1, 2, 3, B를 입력하면 해당하는 기능을 반환한다.") + @Test + void getLineOption() { + String input = "1"; + + SectionOption option = SectionOption.getOption(input); + + assertThat(option).isEqualTo(SectionOption.CREATE); + } + + @DisplayName("목록에 없는 옵션을 선택할 경우 예외가 발생한다.") + @Test + void lineOptionException() { + String input = "1241"; + + assertThatThrownBy(() -> SectionOption.getOption(input)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("옵션이 CREATE 상태이면 true를 반환한다.") + @Test + void getCreateOption() { + String input = "1"; + + SectionOption option = SectionOption.getOption(input); + + assertThat(option.isCreate()).isTrue(); + } + + @DisplayName("옵션이 DELETE 상태이면 true를 반환한다.") + @Test + void getDeleteOption() { + String input = "2"; + + SectionOption option = SectionOption.getOption(input); + + assertThat(option.isDelete()).isTrue(); + } + + @DisplayName("옵션이 Back 상태이면 true를 반환한다.") + @Test + void getBackOption() { + String input = "B"; + + SectionOption option = SectionOption.getOption(input); + + assertThat(option.isBack()).isTrue(); + } +} From e3e0dcdcdc613f36fbdfbd0ebf5728793d8b1636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 14:48:11 +0900 Subject: [PATCH 69/70] =?UTF-8?q?test(SectionRepository):=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EC=B6=94=EA=B0=80=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/line/LineRepository.java | 2 +- .../subway/section/SectionRepositoryTest.java | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/test/java/subway/section/SectionRepositoryTest.java diff --git a/src/main/java/subway/line/LineRepository.java b/src/main/java/subway/line/LineRepository.java index 6d97b4895..c3edc7d26 100644 --- a/src/main/java/subway/line/LineRepository.java +++ b/src/main/java/subway/line/LineRepository.java @@ -52,7 +52,7 @@ public static void deleteStopStation(Name lineName, Station station) { line.deleteStopStation(station); } - private static Line findLineByName(Name name) { + public static Line findLineByName(Name name) { return lines.stream() .filter(line -> line.isSame(name)) .findAny() diff --git a/src/test/java/subway/section/SectionRepositoryTest.java b/src/test/java/subway/section/SectionRepositoryTest.java new file mode 100644 index 000000000..12a1163b7 --- /dev/null +++ b/src/test/java/subway/section/SectionRepositoryTest.java @@ -0,0 +1,57 @@ +package subway.section; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import subway.line.Line; +import subway.line.LineRepository; +import subway.line.StopStations; +import subway.station.Name; +import subway.station.Station; +import subway.station.StationRepository; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SectionRepositoryTest { + + @BeforeAll + public static void initStations() { + StationRepository.addStation(new Name("범계역")); + StationRepository.addStation(new Name("금정역")); + StationRepository.addStation(new Name("산본역")); + + Station upBound = StationRepository.findByName(new Name("범계역")); + Station descending = StationRepository.findByName(new Name("금정역")); + StopStations stopStations = new StopStations(List.of(upBound, descending)); + + LineRepository.addLine(new Name("4호선"), stopStations); + } + + @DisplayName("구간을 추가한다.") + @Test + void addSection() { + Name lineName = new Name("4호선"); + Name stationName = new Name("산본역"); + int index = 2; + + SectionService sectionService = new SectionService(); + sectionService.create(lineName, stationName, index); + + assertThat(LineRepository.lines().size()).isEqualTo(1); + } + + @DisplayName("구간을 삭제한다.") + @Test + void deleteSection() { + Name lineName = new Name("4호선"); + Name stationName = new Name("범계역"); + SectionService sectionService = new SectionService(); + + sectionService.delete(lineName, stationName); + Station station = StationRepository.findByName(stationName); + + assertThat(LineRepository.findLineByName(lineName).isContainStation(station)).isFalse(); + } +} From e8de46a8297d2a975041dfaf0631cb31dd7c8105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Tue, 5 Sep 2023 14:57:56 +0900 Subject: [PATCH 70/70] =?UTF-8?q?refactor(InputView):=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/subway/section/SectionController.java | 2 ++ src/main/java/subway/view/section/SectionInputView.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/subway/section/SectionController.java b/src/main/java/subway/section/SectionController.java index cb0d05337..a163184ff 100644 --- a/src/main/java/subway/section/SectionController.java +++ b/src/main/java/subway/section/SectionController.java @@ -48,6 +48,7 @@ private void createSection(SectionOption option) { int index = readIndex(); sectionService.create(lineName, stationName, index); outputView.printCreateSection(); + outputView.printNewLine(); } } @@ -76,6 +77,7 @@ private void deleteSection(SectionOption option) { if (option.isDelete()) { sectionService.delete(readDeleteLine(), readDeleteStation()); outputView.printDeleteSection(); + outputView.printNewLine(); } } diff --git a/src/main/java/subway/view/section/SectionInputView.java b/src/main/java/subway/view/section/SectionInputView.java index 8cbff7c16..b20d33a28 100644 --- a/src/main/java/subway/view/section/SectionInputView.java +++ b/src/main/java/subway/view/section/SectionInputView.java @@ -26,7 +26,7 @@ public Name readStationName() { } public int readIndex() { - return scanner.nextInt(); + return Integer.parseInt(scanner.nextLine()); } public Name readDeleteLine() {