-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[다리 건너기] 김민겸 미션 제출합니다. #9
base: main
Are you sure you want to change the base?
Conversation
public void printMap(List<Move> moves) { | ||
List<String> up = new ArrayList<>(); | ||
List<String> down = new ArrayList<>(); | ||
for (Move move : moves) { | ||
if (move.direction().equals("U")) { | ||
up.add(move.success()); | ||
down.add(NONE); | ||
} | ||
if (move.direction().equals("D")) { | ||
up.add(NONE); | ||
down.add(move.success()); | ||
} | ||
} | ||
ConsoleWriter.printlnMessage(generateSingleMapRow(up)); | ||
ConsoleWriter.printlnMessage(generateSingleMapRow(down)); | ||
ConsoleWriter.println(); | ||
} |
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.
함수가 너무 길다! 어떻게 해결할 수 있을까?
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.
public void printMap(List<Move> moves) { | |
List<String> up = new ArrayList<>(); | |
List<String> down = new ArrayList<>(); | |
for (Move move : moves) { | |
if (move.direction().equals("U")) { | |
up.add(move.success()); | |
down.add(NONE); | |
} | |
if (move.direction().equals("D")) { | |
up.add(NONE); | |
down.add(move.success()); | |
} | |
} | |
ConsoleWriter.printlnMessage(generateSingleMapRow(up)); | |
ConsoleWriter.printlnMessage(generateSingleMapRow(down)); | |
ConsoleWriter.println(); | |
} | |
public void printMap(List<Move> moves) { | |
List<String> up = new ArrayList<>(); | |
List<String> down = new ArrayList<>(); | |
for (Move move : moves) { | |
moveUp(up, down, move); | |
moveDown(up, down, move); | |
} | |
ConsoleWriter.printlnMessage(generateSingleMapRow(up)); | |
ConsoleWriter.printlnMessage(generateSingleMapRow(down)); | |
ConsoleWriter.println(); | |
} | |
private void moveDown(List<String> up, List<String> down, Move move) { | |
if (move.direction().equals("D")) { | |
up.add(NONE); | |
down.add(move.success()); | |
} | |
} | |
private void moveUp(List<String> up, List<String> down, Move move) { | |
if (move.direction().equals("U")) { | |
up.add(move.success()); | |
down.add(NONE); | |
} | |
} |
public static void validateRange( | ||
int number, | ||
int start, | ||
int end, | ||
ErrorMessage errorMessage | ||
) { | ||
if (isInvalidRange(number, start, end)) { | ||
throw CustomException.from(errorMessage); | ||
} | ||
} |
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.
메서드의 파라미터는 최대 3개까지만 허용한다.
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.
이러한 경우 에러 메시지를 범위 검증에 맞는 것을 따로 만들고, 에러 메시지에 대한 파라미터를 지우는 것을 차선책으로 한다
return new Move(direction, "X"); | ||
} | ||
return new Move(direction, "O"); |
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.
컨트롤러에서 뷰 단의 출력까지 책임지고 있는 형태이다.
boolean 등의 변수로 넘긴 다음에 뷰에서 분기하여 O, X를 출력하는 것이 바람직하다
public String generateSingleMapRow(List<String> map) { | ||
int size = map.size(); | ||
if (size == 1) { | ||
return "[ " + map.get(0) + " ]"; | ||
} | ||
String head = "[ " + map.get(0); | ||
for (int i = 1; i < size; i++) { | ||
head += String.format(SINGLE_MAP_FORMAT, map.get(i)); | ||
} | ||
return head + " ]"; | ||
} |
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.
StringJoiner
로 간결하게 작성할 수 있다.
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.
public String generateSingleMapRow(List<String> map) { | |
int size = map.size(); | |
if (size == 1) { | |
return "[ " + map.get(0) + " ]"; | |
} | |
String head = "[ " + map.get(0); | |
for (int i = 1; i < size; i++) { | |
head += String.format(SINGLE_MAP_FORMAT, map.get(i)); | |
} | |
return head + " ]"; | |
} | |
public String generateSingleMapRow(List<String> map) { | |
String result = new StringJoiner(" | ", "[", "]"); | |
for(String mp : map) { | |
result.add(mp); | |
} | |
} |
No description provided.