Skip to content

Commit

Permalink
지하철 등록 techeer-sv#7 refactor : SubwayUtils 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
heondong9265 committed May 31, 2024
1 parent 3cb1a0b commit f8040b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/main/java/subway/config/SubwayInitializer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package subway.config;

import subway.service.SubwayService;
import subway.util.SubwayUtils;

public class SubwayInitializer {
private final SubwayService subwayService;
Expand All @@ -15,19 +16,18 @@ public void initialize() {
}

private void initializeStations() {
subwayService.addStation("교대역");
subwayService.addStation("강남역");
subwayService.addStation("역삼역");
subwayService.addStation("남부터미널역");
subwayService.addStation("양재역");
subwayService.addStation("양재시민의숲역");
subwayService.addStation("매봉역");
SubwayUtils.addStations(subwayService,
"교대역", "강남역", "역삼역",
"남부터미널역", "양재역", "양재시민의숲역", "매봉역"
);
}

private void initializeLines() {
subwayService.addLine("2호선", new String[]{"교대역", "강남역", "역삼역"});
subwayService.addLine("3호선", new String[]{"교대역", "남부터미널역", "양재역", "매봉역"});
subwayService.addLine("신분당선", new String[]{"강남역", "양재역", "양재시민의숲역"});
SubwayUtils.addLines(subwayService, new Object[][]{
{"2호선", new String[]{"교대역", "강남역", "역삼역"}},
{"3호선", new String[]{"교대역", "남부터미널역", "양재역", "매봉역"}},
{"신분당선", new String[]{"강남역", "양재역", "양재시민의숲역"}}
});
}

}
20 changes: 20 additions & 0 deletions src/main/java/subway/util/SubwayUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package subway.util;

import subway.service.SubwayService;

public class SubwayUtils {

public static void addStations(SubwayService subwayService, String... stations) {
for (String station : stations) {
subwayService.addStation(station);
}
}

public static void addLines(SubwayService subwayService, Object[][] lines) {
for (Object[] line : lines) {
String lineName = (String) line[0];
String[] stations = (String[]) line[1];
subwayService.addLine(lineName, stations);
}
}
}

0 comments on commit f8040b4

Please sign in to comment.