Open
Conversation
Mingyum-Kim
commented
Dec 13, 2023
Comment on lines
+26
to
+42
| 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(); | ||
| } |
Author
There was a problem hiding this comment.
Suggested change
| 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); | |
| } | |
| } |
Comment on lines
+18
to
+27
| public static void validateRange( | ||
| int number, | ||
| int start, | ||
| int end, | ||
| ErrorMessage errorMessage | ||
| ) { | ||
| if (isInvalidRange(number, start, end)) { | ||
| throw CustomException.from(errorMessage); | ||
| } | ||
| } |
Author
There was a problem hiding this comment.
이러한 경우 에러 메시지를 범위 검증에 맞는 것을 따로 만들고, 에러 메시지에 대한 파라미터를 지우는 것을 차선책으로 한다
Comment on lines
+72
to
+74
| return new Move(direction, "X"); | ||
| } | ||
| return new Move(direction, "O"); |
Author
There was a problem hiding this comment.
컨트롤러에서 뷰 단의 출력까지 책임지고 있는 형태이다.
boolean 등의 변수로 넘긴 다음에 뷰에서 분기하여 O, X를 출력하는 것이 바람직하다
Mingyum-Kim
commented
Dec 15, 2023
Comment on lines
+44
to
+54
| 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 + " ]"; | ||
| } |
Author
There was a problem hiding this comment.
StringJoiner로 간결하게 작성할 수 있다.
Author
There was a problem hiding this comment.
Suggested change
| 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); | |
| } | |
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.