-
Notifications
You must be signed in to change notification settings - Fork 133
Code Review #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Oilwoo
wants to merge
6
commits into
woowacourse-precourse:main
Choose a base branch
from
Oilwoo:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code Review #4
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
695e6d6
feat: add template
Oilwoo 06807bd
feat: add to input MonthAndDayOfWeek
Oilwoo 935c6b3
feat: add to input Roster
Oilwoo fa87d72
feat: add to make MonthlyRoster and print it
Oilwoo 82a091a
refactor: remove unused class
Oilwoo 6f7cb1f
docs: write solving strategy
Oilwoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,35 @@ | ||
| ### 미션 해결 전략 | ||
| #### 1. 본인이 이해하고 구현한 내용에 기반해 '다른 근무자와 순서를 바꿔야 하는 경우'를 자신만의 예시를 들어 설명하세요. (필수) | ||
| 우선 평일순번과 주말순번을 돌다보면 겹치는 상황이 발생할 것 이고, 요구사항에 따라 다음 순서의 근무자와 교체 후 당번을 만들면 된다고 생각했습니다. | ||
| 가장 쉬운 예시로 | ||
| 휴일이 없는 4,월 을 기준으로 | ||
|
|
||
| 4,월 | ||
| 평일 비상 근무 순번대로 사원 닉네임을 입력하세요> 준팍,도밥,고니,수아,루루,글로,솔로스타 | ||
| 휴일 비상 근무 순번대로 사원 닉네임을 입력하세요> 준팍,도밥,고니,수아,루루,글로,솔로스타 | ||
|
|
||
| 이러한 형태로 입력하게 되면 | ||
| 1. 처음 평일 순번 준팍 ~ 루루 | ||
| 2. 처음 주말 순번 준팍, 도밥 | ||
| 3. 그 다음 평일 순번 글로 ~ 고니 | ||
| 4. 금요일이 고니가 되는데 고니는 토요일순번이 되어버려서 근무가 겹칩니다. | ||
| 5. 그래서 이때 고니와 수아의 주말순번을 변경하고 | ||
| 4월 1일 월 준팍 | ||
| 4월 2일 화 도밥 | ||
| 4월 3일 수 고니 | ||
| 4월 4일 목 수아 | ||
| 4월 5일 금 루루 | ||
| 4월 6일 토 준팍 | ||
| 4월 7일 일 도밥 | ||
| 4월 8일 월 글로 | ||
| 4월 9일 화 솔로스타 | ||
| 4월 10일 수 준팍 | ||
| 4월 11일 목 도밥 | ||
| 4월 12일 금 고니 | ||
| 4월 13일 토 수아 -> 원래 고니 순번 | ||
| 4월 14일 일 고니 -> 원래 수아 순번 | ||
| 4월 15일 월 수아 | ||
| 위와 같은 형태가 됩니다. | ||
| 주말에서 평일이 넘어가는 경우도 동일하게 평일순번 위치를 변경하면 문제를 해결할 수 있습니다. | ||
|
|
||
| #### 2. 요구사항에서 제시한 앞의 날짜부터 순서를 변경하는 방법 외에 다른 방법이 있다면 어떤 방식이 있는지, 이 방법은 기존에 제시된 방식과 비교해 어떤 차이가 있는지 설명하세요. (선택) | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| package oncall; | ||
|
|
||
| import oncall.controller.CustomController; | ||
| import oncall.service.CustomService; | ||
| import oncall.view.InputView; | ||
| import oncall.view.OutputView; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| InputView inputView = new InputView(); | ||
| OutputView outputView = new OutputView(); | ||
| CustomService customService = new CustomService(); | ||
|
|
||
| CustomController controller = new CustomController(inputView, outputView, customService); | ||
| controller.run(); | ||
| } | ||
| } |
This file contains hidden or 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,29 @@ | ||
| package oncall.config; | ||
|
|
||
| public enum Holidays { | ||
| NEW_YEARS_DAY(1, 1), // 1월 1일 | ||
| INDEPENDENCE_DAY(3, 1), // 3월 1일 | ||
| CHILDRENS_DAY(5, 5), // 5월 5일 | ||
| MEMORIAL_DAY(6, 6), // 6월 6일 | ||
| LIBERATION_DAY(8, 15), // 8월 15일 | ||
| NATIONAL_FOUNDATION_DAY(10, 3), // 10월 3일 | ||
| HANGUL_DAY(10, 9), // 10월 9일 | ||
| CHRISTMAS_DAY(12, 25); // 12월 25일 | ||
|
|
||
| private final int month; | ||
| private final int day; | ||
|
|
||
| // Constructor | ||
| Holidays(int month, int day) { | ||
| this.month = month; | ||
| this.day = day; | ||
| } | ||
|
|
||
| public int getMonth() { | ||
| return month; | ||
| } | ||
|
|
||
| public int getDay() { | ||
| return day; | ||
| } | ||
| } |
This file contains hidden or 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,44 @@ | ||
| package oncall.controller; | ||
|
|
||
| import java.util.List; | ||
| import oncall.domain.CombinedRoster; | ||
| import oncall.domain.MonthAndDayOfWeek; | ||
| import oncall.domain.MonthlyRoster; | ||
| import oncall.domain.Roster; | ||
| import oncall.domain.Worker; | ||
| import oncall.service.CustomService; | ||
| import oncall.view.InputView; | ||
| import oncall.view.OutputView; | ||
|
|
||
| public class CustomController extends ExceptionLoopController{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 컨벤션 통일위해 린트 설정하고 가는걸 추천해요. |
||
| private final InputView input; | ||
| private final OutputView output; | ||
| private final CustomService service; | ||
|
|
||
| public CustomController(InputView input, OutputView output, CustomService service) { | ||
| this.input = input; | ||
| this.output = output; | ||
| this.service = service; | ||
| } | ||
|
|
||
| public void run() { | ||
| MonthAndDayOfWeek monthAndDayOfWeek = repeatUntilValid(this::getMonthAndDayOfWeek); | ||
| CombinedRoster combinedRoster = repeatUntilValid(this::getRoster); | ||
| List<MonthlyRoster> monthlyRoster = service.makeMonthlyRoster(monthAndDayOfWeek, combinedRoster); | ||
| output.printMonthlyRoster(monthlyRoster); | ||
| } | ||
|
|
||
| private MonthAndDayOfWeek getMonthAndDayOfWeek() { | ||
| output.printGetMonthDayOfWeek(); | ||
| return input.getMonthDayOfWeek(); | ||
| } | ||
|
|
||
| private CombinedRoster getRoster() { | ||
| output.printGetWeekdayRoster(); | ||
| Roster weekdayRoster = input.getRoster(); | ||
| output.printGetWeekendRoster(); | ||
| Roster weekendRoster = input.getRoster(); | ||
|
|
||
| return new CombinedRoster(weekdayRoster, weekendRoster); | ||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
src/main/java/oncall/controller/ExceptionLoopController.java
This file contains hidden or 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,16 @@ | ||
| package oncall.controller; | ||
|
|
||
| import java.util.function.Supplier; | ||
| import oncall.exception.CustomException; | ||
|
|
||
| public abstract class ExceptionLoopController { | ||
| protected <T> T repeatUntilValid(Supplier<T> function) { | ||
| while(true) { | ||
| try { | ||
| return function.get(); | ||
| } catch (CustomException e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,34 @@ | ||
| package oncall.domain; | ||
|
|
||
| import java.util.List; | ||
| import oncall.exception.IllegalInputException; | ||
|
|
||
| public class CombinedRoster { | ||
| private final Roster weekdayRoster; | ||
| private final Roster weekendRoster; | ||
|
|
||
| public CombinedRoster(Roster weekdayRoster, Roster weekendRoster) { | ||
| validate(weekdayRoster, weekendRoster); | ||
| this.weekdayRoster = weekdayRoster; | ||
| this.weekendRoster = weekendRoster; | ||
| } | ||
|
|
||
| private void validate(Roster weekdayRoster, Roster weekendRoster) { | ||
| List<Worker> weekdayWorkers = weekdayRoster.getWorkers(); | ||
| List<Worker> weekendWorkers = weekendRoster.getWorkers(); | ||
|
|
||
| if(weekdayWorkers.size() != weekendWorkers.size()){ | ||
| throw new IllegalInputException(); | ||
| } | ||
| // 중복 검사 로직은 나중에 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Roster에 중복 검사 로직이 구현되지 않았나요? |
||
| } | ||
|
|
||
| public Roster getWeekdayRoster() { | ||
| return weekdayRoster; | ||
| } | ||
|
|
||
| public Roster getWeekendRoster() { | ||
| return weekendRoster; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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,36 @@ | ||
| package oncall.domain; | ||
|
|
||
| import java.time.DayOfWeek; | ||
| import java.time.Month; | ||
| import java.time.format.TextStyle; | ||
| import java.util.Locale; | ||
|
|
||
| public class MonthAndDayOfWeek { | ||
| private final Month month; | ||
| private final DayOfWeek dayOfWeek; | ||
|
|
||
| public MonthAndDayOfWeek(Month month, DayOfWeek dayOfWeek) { | ||
| this.month = month; | ||
| this.dayOfWeek = dayOfWeek; | ||
| } | ||
|
|
||
| public int getMonthNumber(){ | ||
| return month.getValue(); | ||
| } | ||
|
|
||
| public int getLastDay() { | ||
| return month.minLength(); | ||
| } | ||
|
|
||
| public int getDayOfWeekNumber() { | ||
| return dayOfWeek.getValue(); | ||
| } | ||
|
|
||
| public String getDayOfWeekName() { | ||
| return dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.KOREAN); | ||
| } | ||
|
|
||
| public DayOfWeek getDayOfWeek() { | ||
| return dayOfWeek; | ||
| } | ||
| } |
This file contains hidden or 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,30 @@ | ||
| package oncall.domain; | ||
|
|
||
| public class MonthlyRoster { | ||
| private final int month; | ||
| private final int day; | ||
| private final String dayOfWeek; | ||
| private final String name; | ||
| private final boolean holiday; | ||
|
|
||
| public MonthlyRoster(int month, int day, String dayOfWeek, String name, boolean holiday) { | ||
| this.month = month; | ||
| this.day = day; | ||
| this.dayOfWeek = dayOfWeek; | ||
| this.name = name; | ||
| this.holiday = holiday; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.valueOf(month) + "월 " + String.valueOf(day) + "일 " + dayOfWeek + isHoliday() + name; | ||
| } | ||
|
|
||
| private String isHoliday() { | ||
| //주말은 아님 | ||
| if (holiday && !(dayOfWeek.equals("토") || dayOfWeek.equals("일"))) { | ||
| return "(휴일) "; | ||
| } | ||
| return " "; | ||
| } | ||
| } |
This file contains hidden or 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,52 @@ | ||
| package oncall.domain; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import oncall.exception.IllegalInputException; | ||
|
|
||
| public class Roster { | ||
| private final List<Worker> workers; | ||
| private static final int WORKERS_MIN_SIZE = 5; | ||
| private static final int WORKERS_MAX_SIZE = 35; | ||
|
|
||
|
|
||
| public Roster(List<Worker> workers) { | ||
| validate(workers); | ||
| this.workers = workers; | ||
| } | ||
|
|
||
| private void validate(List<Worker> workers) { | ||
| if (workers.size() < WORKERS_MIN_SIZE || workers.size() > WORKERS_MAX_SIZE) { | ||
| throw new IllegalInputException(); | ||
| } | ||
| checkDuplicate(workers); | ||
| } | ||
|
|
||
| private void checkDuplicate(List<Worker> workers) { | ||
| Set<String> names = new HashSet<>(); | ||
| for (Worker w : workers) { | ||
| names.add(w.getName()); | ||
| } | ||
| if (workers.size() != names.size()) { | ||
| throw new IllegalInputException(); | ||
| } | ||
| } | ||
|
|
||
| public List<Worker> getWorkers() { | ||
| return workers; | ||
| } | ||
|
|
||
| public String getWorkerNameByIndex(int i) { | ||
| return workers.get(i).getName(); | ||
| } | ||
|
|
||
| public void swapRoster(int i) { | ||
| Collections.swap(workers, i, i + 1); | ||
| } | ||
|
|
||
| public int getRosterSize() { | ||
| return workers.size(); | ||
| } | ||
| } |
This file contains hidden or 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,24 @@ | ||
| package oncall.domain; | ||
|
|
||
| import oncall.exception.IllegalNameException; | ||
|
|
||
| public class Worker { | ||
| private static final int NAME_LENGTH = 5; | ||
|
|
||
| private final String name; | ||
|
|
||
| public Worker(String name){ | ||
| validate(name); | ||
| this.name = name; | ||
| } | ||
|
|
||
| private void validate(String name) { | ||
| if(name.length() > NAME_LENGTH){ | ||
| throw new IllegalNameException(); | ||
| } | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
This file contains hidden or 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,9 @@ | ||
| package oncall.exception; | ||
|
|
||
| public class CustomException extends IllegalArgumentException{ | ||
| private static final String ERROR_PREFIX = "[ERROR] "; | ||
|
|
||
| CustomException(String message){ | ||
| super(ERROR_PREFIX + message); | ||
| } | ||
| } |
This file contains hidden or 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,7 @@ | ||
| package oncall.exception; | ||
|
|
||
| public class IllegalInputException extends CustomException { | ||
| public IllegalInputException() { | ||
| super("유효하지 않은 입력 값입니다. 다시 입력해 주세요."); | ||
| } | ||
| } |
This file contains hidden or 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,7 @@ | ||
| package oncall.exception; | ||
|
|
||
| public class IllegalNameException extends CustomException { | ||
| public IllegalNameException() { | ||
| super("이름이 5자 초과입니다. 다시 입력해 주세요."); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 경우 예외 처리가 안되어 있네요.