Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
67acfb9
docs: 기본 기능 및 모델링에 대한 README.md 작성
sjiwon Jun 25, 2023
d1eef0e
feat: Baseballs 관련 상수 인터페이스 구현
sjiwon Jun 25, 2023
7077cce
feat: Baseballs 모델 구현 및 예외 케이스 검증
sjiwon Jun 25, 2023
bd0fecc
test: Baseballs 테스트 케이스 작성
sjiwon Jun 25, 2023
2da9bf0
feat: Computer 모델 구현 및 테스트 케이스 작성
sjiwon Jun 25, 2023
312f766
feat: User 모델 구현 및 테스트 케이스 작성
sjiwon Jun 25, 2023
55bee8e
feat: 게임 결과 명세를 위한 Result 모델 구현
sjiwon Jun 25, 2023
6ffb501
feat: 게임 결과 도출을 위한 Referee 모델 구현 및 테스트 케이스 작성
sjiwon Jun 25, 2023
1dde87d
feat: 게임 진행 상태 Tracking을 위한 GameStatus 구현 및 테스트 케이스 작성
sjiwon Jun 25, 2023
7a3481e
feat: 게임 재시작 관련 GameProcessDecider 구현 및 테스트 케이스 작성
sjiwon Jun 25, 2023
ed74d6e
feat: 사용자 Input을 위한 InputView 구현
sjiwon Jun 25, 2023
cb910f1
feat: 콘솔 출력을 위한 OutputView 구현
sjiwon Jun 25, 2023
7150851
feat: 게임 프로세싱을 위한 GameController 및 Application 동작 처리
sjiwon Jun 25, 2023
f28211a
test: Controller 테스트 케이스 추가
sjiwon Jun 25, 2023
7f0707b
refactor: 사용자 숫자 Input시 Baseballs 수만큼 입력했는지 검증 추가
sjiwon Jun 25, 2023
b0dabea
refactor: 사용자 Input에 대한 Length 검증 -> 공백 존재 검증 케이스로 수정
sjiwon Jun 25, 2023
ba99c7e
refactor: SPACE -> SEPARATOR 네이밍 수정
sjiwon Jun 29, 2023
36107ff
fix: 컴퓨터 Baseballs 랜덤 생성 관련 not equal -> less 조건으로 수정
sjiwon Jul 2, 2023
10961ce
test: Computer Baseballs 랜덤 생성 관련 테스트 케이스 추가
sjiwon Jul 2, 2023
e619cf8
refactor: readUserBaseballInput 접근제어자 public -> private
sjiwon Jul 3, 2023
95f69e0
refactor: Computer baseballs 생성 간 내부 로직 메소드화
sjiwon Jul 3, 2023
0e47d89
refactor: Referee strikeCount 계산 로직 간 filter comparing method 분리
sjiwon Jul 3, 2023
d71a429
refactor: ExceptionConstants class -> interface
sjiwon Jul 3, 2023
56cf0e5
refactor: 사용자 Input I/O간 검증 순서 수정
sjiwon Jul 3, 2023
991a5d9
refactor: hasSpace 메소드 위치 수정
sjiwon Jul 3, 2023
bdb2346
fix: UserTest간 new Baseball -> new User로 수정
sjiwon Jul 15, 2023
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
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
### `Baseballs`
- 입력한 3개의 숫자들을 추상화시킨 `Baseballs`
- Baseballs에 속한 `List<Integer>`은
- [ ] 각 원소가 `1..9` 범위 사이여야 한다
- [ ] 원소의 크기가 3이여야 한다
- [ ] 중복된 원소가 없어야 한다
- [X] 각 원소가 `1..9` 범위 사이여야 한다
- [X] 원소의 크기가 3이여야 한다
- [X] 중복된 원소가 없어야 한다

<br>

Expand Down
51 changes: 51 additions & 0 deletions src/main/java/baseball/model/Baseballs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package baseball.model;

import java.util.Collections;
import java.util.List;

import static baseball.utils.BaseballConstants.*;
import static baseball.utils.ExceptionConstants.BaseballException.*;

public class Baseballs {
private final List<Integer> baseballs;

public Baseballs(final List<Integer> baseballs) {
validateEachBaseballElementIsInRange(baseballs);
validateTotalBaseballSize(baseballs);
validateBaseballHasDuplicateNumber(baseballs);
this.baseballs = baseballs;
}

private void validateEachBaseballElementIsInRange(final List<Integer> baseballs) {
if (hasOutOfRange(baseballs)) {
throw new IllegalArgumentException(BASEBALL_IS_NOT_IN_RANGE.message);
}
}

private boolean hasOutOfRange(final List<Integer> baseballs) {
return baseballs.stream()
.anyMatch(baseball -> baseball < MIN_BASEBALL || baseball > MAX_BASEBALL);
}

private void validateTotalBaseballSize(final List<Integer> baseballs) {
if (baseballs.size() != BASEBALL_SIZE) {
throw new IllegalArgumentException(BASEBALL_SIZE_IS_NOT_FULFILL.message);
}
}

private void validateBaseballHasDuplicateNumber(final List<Integer> baseballs) {
if (hasDuplicateNumber(baseballs)) {
throw new IllegalArgumentException(BASEBALL_MUST_BE_UNIQUE.message);
}
}

private boolean hasDuplicateNumber(final List<Integer> baseballs) {
return baseballs.stream()
.distinct()
.count() != BASEBALL_SIZE;
}

public List<Integer> getBaseballs() {
return Collections.unmodifiableList(baseballs);
}
Comment on lines +48 to +50
Copy link
Collaborator

Choose a reason for hiding this comment

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

Collections.unmodifiableList는 Read-only라도 원본 컬렉션의 불변성을 보장하지 않는다고 합니다. CopyOf가 아닌 unmodifiableList를 사용하신 이유가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unmodifiableList를 사용하는거는 원본 객체에 대해서 immutable을 보장하지는 않는데 구조상 Baseballs의 원본 객체를 외부에서 접근할 수 없고 외부에서 얻는 List<Integer> baseballs는 immutable이기 때문에 unmodifiableList를 써도 상관없다고 생각했습니다.

  • copyOf를 안쓴이유는 어차피 외부에서 얻는 baseball은 immutable이 보장되기 때문에 굳이 매번 복사할 필요가 없다고 생각

}
16 changes: 16 additions & 0 deletions src/main/java/baseball/utils/ExceptionConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package baseball.utils;

public class ExceptionConstants {
public enum BaseballException {
BASEBALL_IS_NOT_IN_RANGE("숫자는 1..9 범위만 허용합니다."),
BASEBALL_SIZE_IS_NOT_FULFILL("숫자 3개를 입력해주세요."),
BASEBALL_MUST_BE_UNIQUE("중복된 숫자는 허용하지 않습니다."),
;

public final String message;

BaseballException(final String message) {
this.message = message;
}
}
}