-
Notifications
You must be signed in to change notification settings - Fork 251
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
[2단계 - 사다리 타기] 이든(최승준) 미션 제출합니다. #366
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
65cc025
refactor : 클래스명이 의미를 더 잘 표현하도록 수정
PgmJun 7226a19
refactor : 오라클 자바 컨벤션에 맞도록 클래스 멤버 위치 조정
PgmJun d8cbe46
refactor : 중복되는 네이밍 변경
PgmJun 9ab2f29
refactor : BridgeGeneratorStub 클래스, NPE 문제 방지
PgmJun 8cc519d
remove : 입력 테스트 제거
PgmJun b46f1d5
docs : Step2 기능 구현 문서 추가
PgmJun 94292ee
feat : 사다리 결과 출력 기능 구현
PgmJun 4c13691
refactor : 참가자 이름 입력 시, 구분자가 가장 마지막에 오는 경우 검증하도록 수정
PgmJun d52cf71
refactor : 패키지 구조 변경
PgmJun 55d9d3d
feat : 사다리 실행 결과 확인 기능 구현
PgmJun 585db12
refactor : CustomException 제거
PgmJun fef4282
refactor : 예외 메시지는 발생시키는 곳에서 관리하도록 변경
PgmJun c021e37
refactor : 상수 네이밍 깔끔하게 변경
PgmJun fa2fd59
refactor : 중복되는 bridge 랜덤 생성 로직 메서드 분리
PgmJun 0f8e40f
remove : 의미없는 상수 제거
PgmJun e44fd39
feat : 사용할 수 없는 이름 추가
PgmJun 027deda
refactor : 재입력 메서드 네이밍 동일하게 변경(오버로딩)
PgmJun 62b6580
refactor : 커맨드 관련 상수 열거 클래스로 분리
PgmJun a61097e
refactor : 필드명으로 value 사용
PgmJun c22e650
refactor : 불필요한 확장성을 위해 만든 RetryableController 삭제
PgmJun 6e8f2cf
refactor : InputView에서만 사용되는 상수에 private 접근 제어 설정
PgmJun c38d1bd
refactor : 코드라인 정리
PgmJun 3dfe45e
refactor : 코드 컨벤션에 맞춰 클래스 멤버 위치 조정
PgmJun 17f859e
refactor : ui 로직에 의존하던 LadderBridge enum 코드 제거
PgmJun d44bbbd
refactor : Players 사다리 결과 형식 상수화
PgmJun bca81d8
docs : 사다리 종료 커멘드 관련 문서 수정
PgmJun 9543acc
remove : LadderBridge getter 삭제
PgmJun 65a578c
refactor : 오라클 컨벤션에 맞게 멤버 위치 변경
PgmJun ea3e039
refactor : 테스트 클래스 위치, 네이밍 수정
PgmJun 04f71c7
refactor : 테스트 내부 클래스로 분리
PgmJun 48c6982
refactor : 중복 로직 메서드 분리
PgmJun 5c2a355
refactor : final 키워드 사용해서 재할당 불가능하게 수정
PgmJun dc65b6e
refactor : final 키워드 사용해서 재할당 불가능하게 수정
PgmJun 7b9f32b
refactor : 직관적인 에러 메시지 네이밍 사용
PgmJun 4359d9d
refactor : ealry return 적용하여 else 키워드 제거
PgmJun 120d838
refactor : Ladder의 책임 분리
PgmJun f96ca82
refactor : 한번에 index, name 조회해오도록 변경
PgmJun 9b281d0
refactor : 클래스 변수, 인스턴스 변수 구분
PgmJun 1ba0367
refactor : n번 조회 방식에서 단일 조회 방식으로 변경
PgmJun 9670383
refactor : OS 별로 다른 이스케이프 문자 고려하여 코드 수정
PgmJun 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 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
This file contains 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
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
src/main/java/common/exception/message/ExceptionMessage.java
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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,45 +1,110 @@ | ||
package controller; | ||
|
||
import domain.Ladder; | ||
import domain.LadderHeight; | ||
import domain.PlayerName; | ||
import domain.PlayerNames; | ||
import common.exception.model.IOException; | ||
import domain.bridge.strategy.RandomBridgeGenerator; | ||
import domain.ladder.Ladder; | ||
import domain.ladder.LadderHeight; | ||
import domain.ladder.LadderResults; | ||
import domain.player.PlayerName; | ||
import domain.player.PlayerNames; | ||
import view.InputView; | ||
import view.OutputView; | ||
import view.command.Command; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public class LadderController extends Controller { | ||
public class LadderController { | ||
public static final int READ_LIMIT = 10; | ||
public static final String READ_LIMIT_OVER = String.format("입력 횟수 제한(%d)를 초과하였습니다", READ_LIMIT); | ||
|
||
private final InputView inputView; | ||
private final OutputView outputView; | ||
private int retryCount; | ||
|
||
public LadderController(InputView inputView, OutputView outputView) { | ||
super(inputView, outputView); | ||
this.inputView = inputView; | ||
this.outputView = outputView; | ||
this.retryCount = 0; | ||
} | ||
|
||
public Ladder createLadder() { | ||
PlayerNames playerNames = readPlayerNames(); | ||
LadderHeight ladderHeight = readLadderHeight(); | ||
|
||
Ladder ladder = Ladder.create(ladderHeight, playerNames, new RandomBridgeGenerator()); | ||
outputView.printLadder(playerNames, ladder); | ||
public Ladder createLadder(final LadderHeight ladderHeight, final PlayerNames playerNames, final LadderResults results) { | ||
Ladder ladder = Ladder.create(ladderHeight, playerNames.getCount(), new RandomBridgeGenerator()); | ||
outputView.printGeneratedLadder(ladder, playerNames, results); | ||
|
||
return ladder; | ||
} | ||
|
||
private PlayerNames readPlayerNames() { | ||
public PlayerNames readPlayerNames() { | ||
return retry(() -> createPlayerNames(inputView.readPlayerNames())); | ||
} | ||
|
||
public PlayerNames createPlayerNames(String[] playerNamesInput) { | ||
private PlayerNames createPlayerNames(final String[] playerNamesInput) { | ||
List<PlayerName> playerNames = Arrays.stream(playerNamesInput) | ||
.map(PlayerName::new) | ||
.toList(); | ||
|
||
return new PlayerNames(playerNames); | ||
} | ||
|
||
private LadderHeight readLadderHeight() { | ||
public LadderHeight readLadderHeight() { | ||
return retry(() -> new LadderHeight(inputView.readLadderHeight())); | ||
} | ||
|
||
public LadderResults readLadderResults(final int playerCount) { | ||
return retry(() -> new LadderResults(inputView.readLadderResults(), playerCount)); | ||
} | ||
|
||
public void matchPlayerToResult(final Ladder ladder, final PlayerNames playerNames, final LadderResults results) { | ||
retry(() -> findPlayerResult(ladder, playerNames, results)); | ||
outputView.printEndMessage(); | ||
} | ||
|
||
private void findPlayerResult(final Ladder ladder, final PlayerNames playerNames, final LadderResults results) { | ||
String inputPlayerName = inputView.readPlayerNameForGetResult(); | ||
|
||
while (!Command.isFinishCommand(inputPlayerName)) { | ||
outputView.printPlayerLadderResult(getPlayerLadderResult(inputPlayerName, ladder, playerNames, results)); | ||
inputPlayerName = inputView.readPlayerNameForGetResult(); | ||
} | ||
} | ||
|
||
private Map<String, String> getPlayerLadderResult(final String inputPlayerName, final Ladder ladder, | ||
final PlayerNames playerNames, final LadderResults results) { | ||
if (Command.isAllCommand(inputPlayerName)) { | ||
return ladder.findAllPlayersLadderResultValue(playerNames, results); | ||
} | ||
return ladder.findSinglePlayerLadderResultValue(inputPlayerName, playerNames, results); | ||
} | ||
|
||
<R> R retry(final Supplier<R> supplier) { | ||
validateRetryCountLimit(); | ||
try { | ||
R value = supplier.get(); | ||
retryCount = 0; | ||
return value; | ||
} catch (Exception exception) { | ||
outputView.printErrorMessage(exception.getMessage()); | ||
return retry(supplier); | ||
} | ||
} | ||
|
||
void retry(final Runnable runnable) { | ||
validateRetryCountLimit(); | ||
try { | ||
runnable.run(); | ||
retryCount = 0; | ||
} catch (Exception exception) { | ||
outputView.printErrorMessage(exception.getMessage()); | ||
retry(runnable); | ||
} | ||
} | ||
|
||
private void validateRetryCountLimit() { | ||
if (retryCount++ == READ_LIMIT) { | ||
throw new IOException(READ_LIMIT_OVER); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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.
의미가 드러나지 않는 경우에 사용한다는거에 공감을 하고 더 나아가서 유지보수측면에서도 좋다고생각합니다. 예를 들어, 한 군데에서만 사용되고있는 숫자가 로직이 발전되면서 다른곳에서도 같은 숫자를 쓰게되는경우가 있을거에요. 요구사항 변경으로 해당 숫자를 변경해야할때 모두 찾아서 수정해주어야합니다. 실수로 한군데라도 빠트리게되면 버그가 생기겠죠.
그리고 문서화측면(self-documenting)에서도 좋습니다. 상수만보고 코드가 어떤 일들을 하는지 알 수 있습니다. 마지막으로 보안측면도있는데요, 값을 변경할 수 없으므로 런타임때 값이 의도치않게 바뀌는걸 막아줍니다.
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.
상황에 따라 다르다고생각해요. 1차적으로는 저도 사용하는곳에서 관리를 해야 관리가 편하다고생각하는데요, 다른곳에서도 그 상수를 참조할경우에는 공통으로 만드는게 낫겟죠. 다만 필요해지는 순간에 공통으로 정의합니다.
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.
필요해지는 순간에 공통으로 라는 말에 공감합니다! 좋은 의견 감사합니다.