-
Notifications
You must be signed in to change notification settings - Fork 1.1k
lotto - step3 #4172
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
lotto - step3 #4172
Conversation
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.
안녕하세요 성수님 😄
미션 잘 진행해주셨네요! 몇가지 코멘트 남겨두었으니 다음 미션 진행하시면 함께 확인부탁드려요 :)
궁금하거나 고민이 되는 부분이 있으시다면 언제든 pr 코멘트 또는 dm으로 요청 부탁드립니다.
감사합니다 🙇♂️
|
||
import java.util.Objects; | ||
|
||
public class LottoNumber { |
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.
value object 👍
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public enum Rank { |
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.
잘 옮겨주셨네요 👍
THIRD(Arrays.asList(5), 1_500_000, false), | ||
FOURTH(Arrays.asList(4), 50_000, false), | ||
FIFTH(Arrays.asList(3), 5_000, false), | ||
MISS(Arrays.asList(0, 1, 2), 0, false); |
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.
👍
if (countOfMatch > 6) { | ||
throw new IllegalArgumentException("일치하는 번호는 최대 6개까지만 가능합니다."); | ||
} | ||
|
||
if (countOfMatch == 5) { | ||
return matchBonus ? SECOND : THIRD; | ||
} | ||
|
||
return Arrays.stream(values()) | ||
.filter(rank -> rank.matchCounts.contains(countOfMatch)) | ||
.findFirst() | ||
.orElse(MISS); | ||
} |
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.
stream 한번으로 모두 처리할 수 있어보여요!
- matchCounts가 포함되는 경우 필터링
- bonus가 일치하는 경우 필터링
- 모두 아니면 예외처리
if (numbers.size() != LOTTO_SIZE) { | ||
throw new IllegalArgumentException("로또 번호는 6개여야 합니다."); | ||
} | ||
public static Lotto of(List<Integer> numbers) { |
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개인 경우 from
을 사용합니다. 파라메터가 여러개일 때 of
를 사용하여요.
영문표현과 연관있는 관습이라고 봐주시면 좋을 것 같네요 😄
감사합니다.