forked from techeer-sv/Infinite_Challenge_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 지하철역 교대역, 강남역 등 명시 내용 등록 - 지하철 노선 2호선, 3호선, 신분당선 등록 - 노선 초기 설정 역 등록 Closes techeer-sv#1, techeer-sv#2, techeer-sv#3
- Loading branch information
1 parent
70aede1
commit 3e47622
Showing
5 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package subway.data; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import subway.domain.Line; | ||
import subway.domain.LineRepository; | ||
import subway.domain.Section; | ||
import subway.domain.SectionRepository; | ||
import subway.domain.Station; | ||
import subway.domain.StationRepository; | ||
|
||
public class DataInitializer { | ||
private final LineRepository lineRepository; | ||
private final StationRepository stationRepository; | ||
private final SectionRepository sectionRepository; | ||
|
||
public DataInitializer() { | ||
this.lineRepository = new LineRepository(); | ||
this.stationRepository = new StationRepository(); | ||
this.sectionRepository = new SectionRepository(); | ||
} | ||
|
||
|
||
public void initializeStations() { | ||
List<String> stationData = List.of("교대역", "강남역", "역삼역", "남부터미널역", "양재역", "양재시민의숲역", "매봉역"); | ||
stationData.forEach(stationName -> stationRepository.addStation(new Station(stationName))); | ||
} | ||
|
||
public void initializeLines() { | ||
Map<String, List<String>> lineData = Map.of( | ||
"2호선", List.of("교대역", "강남역", "역삼역"), | ||
"3호선", List.of("교대역", "남부터미널역", "양재역", "매봉역"), | ||
"신분당선", List.of("강남역", "양재역", "양재시민의숲역") | ||
); | ||
|
||
lineData.forEach((lineName, stationNames) -> { | ||
Line line = new Line(lineName); | ||
Section section = new Section(line); | ||
stationNames.forEach(stationName -> section.addStation(new Station(stationName))); | ||
lineRepository.addLine(line); | ||
sectionRepository.addSection(section); | ||
}); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package subway.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Section { | ||
private Line line; | ||
private List<Station> stations; | ||
|
||
public Section(Line line) { | ||
this.line = line; | ||
this.stations = new ArrayList<>(); | ||
} | ||
|
||
public void addStation(Station station) { | ||
stations.add(station); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package subway.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SectionRepository { | ||
private static final List<Section> sections = new ArrayList<>(); | ||
|
||
public static void addSection(Section section) {sections.add(section);} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package subway.service; | ||
|
||
import subway.data.DataInitializer; | ||
|
||
public class SubwayService { | ||
private final DataInitializer dataInitializer; | ||
|
||
public SubwayService() { | ||
this.dataInitializer = new DataInitializer(); | ||
} | ||
|
||
public void settingData() { | ||
dataInitializer.initializeStations(); | ||
dataInitializer.initializeLines(); | ||
} | ||
|
||
|
||
|
||
|
||
} |