Skip to content
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

Code Review #4

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Code Review #4

wants to merge 6 commits into from

Conversation

Oilwoo
Copy link

@Oilwoo Oilwoo commented Dec 11, 2024

No description provided.

Copy link

@DWL21 DWL21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/woowacourse-precourse/java-oncall-6/blob/main/README.md
입출력 요구사항에서 예외 케이스 잘 찾고 과제 진행 요구 사항 지키면 좋은 점수 받을 수 있을겁니다.
좋은 결과 있었으면 좋겠네요.

import oncall.view.InputView;
import oncall.view.OutputView;

public class CustomController extends ExceptionLoopController{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컨벤션 통일위해 린트 설정하고 가는걸 추천해요.

Comment on lines +16 to +61
public class CustomService {
public List<MonthlyRoster> makeMonthlyRoster(MonthAndDayOfWeek monthAndDayOfWeek, CombinedRoster combinedRoster) {
int monthNumber = monthAndDayOfWeek.getMonthNumber(); // 5
int lastDay = monthAndDayOfWeek.getLastDay(); // 31

Roster weekdayRoster = combinedRoster.getWeekdayRoster();
Roster weekendRoster = combinedRoster.getWeekendRoster();

int dayOfWeekIndex = monthAndDayOfWeek.getDayOfWeekNumber(); // 월-1 , 일-7
List<MonthlyRoster> monthlyRosters = new ArrayList<>();

int weekdayIndex = 0;
int weekendIndex = 0;
String name = "";
for (int day = 1; day <= lastDay; day++) {
boolean isHoliday = isHoliday(monthNumber, day, dayOfWeekIndex);
if (isHoliday) {
if(name.equals(weekendRoster.getWorkerNameByIndex(weekendIndex))){//이전 근무자와 이름이 연속되는지 확인
weekendRoster.swapRoster(weekendIndex);//연속되면 스왑
}
name = weekendRoster.getWorkerNameByIndex(weekendIndex);
weekendIndex += 1;
if(weekendIndex > weekendRoster.getRosterSize() - 1){ //순번 다 돌면 초기화
weekendIndex = 0;
}
}
if (!isHoliday) {
if(name.equals(weekdayRoster.getWorkerNameByIndex(weekdayIndex))){//이전 근무자와 이름이 연속되는지 확인
weekdayRoster.swapRoster(weekdayIndex);//연속되면 스왑
}
name = weekdayRoster.getWorkerNameByIndex(weekdayIndex);
weekdayIndex += 1;
if(weekdayIndex > weekdayRoster.getRosterSize() - 1){ //순번 다 돌면 초기화
weekdayIndex = 0;
}
}
//리스트에 추가
monthlyRosters.add(new MonthlyRoster(monthNumber, day, getDayOfWeekName(dayOfWeekIndex), name, isHoliday));

//요일 순번 다 돌면 초기화
dayOfWeekIndex += 1;
if (dayOfWeekIndex > 7) {
dayOfWeekIndex = 1;
}
}
return monthlyRosters;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수(또는 메서드)의 길이가 15라인을 넘어가지 않도록 구현한다.
함수(또는 메서드)가 한 가지 일만 하도록 최대한 작게 만들어라.

Comment on lines +69 to +77
private boolean isHoliday(int month, int day, int dayOfWeekNumber) {
for (Holidays h : Holidays.values()) {
if (h.getMonth() == month && h.getDay() == day) {
return true;
}
}
if (DayOfWeek.of(dayOfWeekNumber) == DayOfWeek.SATURDAY || DayOfWeek.of(dayOfWeekNumber) == DayOfWeek.SUNDAY) {
return true;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holidays Enum class에 메서드를 구현하는게 적절해보여요.

if(weekdayWorkers.size() != weekendWorkers.size()){
throw new IllegalInputException();
}
// 중복 검사 로직은 나중에
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roster에 중복 검사 로직이 구현되지 않았나요?

for (int day = 1; day <= lastDay; day++) {
boolean isHoliday = isHoliday(monthNumber, day, dayOfWeekIndex);
if (isHoliday) {
if(name.equals(weekendRoster.getWorkerNameByIndex(weekendIndex))){//이전 근무자와 이름이 연속되는지 확인
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent(인덴트, 들여쓰기) depth를 3이 넘지 않도록 구현한다. 2까지만 허용한다.
예를 들어 while문 안에 if문이 있으면 들여쓰기는 2이다.

@@ -1,5 +1,35 @@
### 미션 해결 전략
#### 1. 본인이 이해하고 구현한 내용에 기반해 '다른 근무자와 순서를 바꿔야 하는 경우'를 자신만의 예시를 들어 설명하세요. (필수)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 경우 예외 처리가 안되어 있네요.

"4,월",
"a,b,c,d,e",
"a,b,c,d,e"

for (int day = 1; day <= lastDay; day++) {
boolean isHoliday = isHoliday(monthNumber, day, dayOfWeekIndex);
if (isHoliday) {
if(name.equals(weekendRoster.getWorkerNameByIndex(weekendIndex))){//이전 근무자와 이름이 연속되는지 확인
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석 대신 코드로 구현 의도를 설명하면 좋겠어요.
메서드를 분리하고 주석의 내용을 메서드 이름으로 하면 되겠네요.

Comment on lines +18 to +20
int monthNumber = monthAndDayOfWeek.getMonthNumber(); // 5
int lastDay = monthAndDayOfWeek.getLastDay(); // 31

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int monthNumber = monthAndDayOfWeek.getMonthNumber(); // 5
int lastDay = monthAndDayOfWeek.getLastDay(); // 31
final int monthNumber = monthAndDayOfWeek.getMonthNumber(); // 5
final int lastDay = monthAndDayOfWeek.getLastDay(); // 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants