Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/ladder/converter/ResultConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

public class ResultConverter {

private ResultConverter() {
}

public static LadderResultDto convertIntoLadderResultDto(
Participants participants,
ExecutionResults executionResults,
Expand Down
47 changes: 27 additions & 20 deletions src/main/java/ladder/model/Direction.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
package ladder.model;

public class Direction {
import ladder.exception.InvalidDirectionException;

private final boolean isLeft;
public enum Direction {
LEFT(-1),
RIGHT(1),
HOLD(0);

private final boolean isRight;
private final int moveCount;

private Direction(boolean isLeft, boolean isRight) {
this.isLeft = isLeft;
this.isRight = isRight;
Direction(int moveCount) {
this.moveCount = moveCount;
}

public static Direction of(boolean isLeft, boolean isRight) {
return new Direction(isLeft, isRight);
}
if (isLeft && isRight) {
throw new InvalidDirectionException();
}

public boolean isLeft() {
return isLeft;
}
if (isLeft) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

enum 을 활용해줌으로써 좀 더 명확한 사용처가 정해지는 것 같네요 👍

return LEFT;
}

public boolean isRight() {
return isRight;
if (isRight) {
return RIGHT;
}

return HOLD;
}

public int move(int index) {
if(isLeft) {
return index - 1;
}
return this.moveCount + index;
}

if(isRight) {
return index + 1;
}
public boolean isRight() {
return this == RIGHT;
}

return index;
public boolean isLeft() {
return this == LEFT;
}

}
2 changes: 1 addition & 1 deletion src/main/java/ladder/view/InputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public String inputParticipantForResult() {
}

private ExecutionResults convertExecutionResults() {
String[] executionResults = readLine().replace(" ", "").split(DEFAULT_DELIMITER);
String[] executionResults = readLine().replace(WHITE_SPACE, BLANK).split(DEFAULT_DELIMITER);
List<ExecutionResult> executionResultList = Arrays.stream(executionResults)
.map(ExecutionResult::create)
.collect(toList());
Expand Down