-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
π 3λ¨κ³ - λ‘λ(2λ±) #3559
base: h3yon
Are you sure you want to change the base?
Conversation
refactor: lotto to lottery
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.
μλ
νμΈμ ν¬μ€λ μ΄λλ§ 3λ¨κ³ λ―Έμ
μ΄λ€μ.
λͺ κ°μ§ νΌλλ°± λ¨κ²¨λλ ΈμΌλ νμΈ ν λ€μ 리뷰μμ² λΆνλ립λλ€!
import static auto.application.MatchedAmount.findByCount; | ||
|
||
public class MatchLottoService { | ||
private static final Map<MatchedAmount, Integer> matchedCountMap = new HashMap<>();// = MatchedAmount.getMatchedCountMap(); |
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.
- μλΉμ€ κ³μΈ΅μ΄λ©΄ μ΅λν 무μν(stateless)κ³μΈ΅ μ€κ³λ₯Ό μ§μν΄λ³΄λ©΄ μ΄λ¨κΉμ? μ¬μ¬μ©μ± μ΄μκ° μμΌλκΉμ
- μ΄ κ²½μ° Enumνμ μ keyλ‘ μ¬μ©νλ€λ©΄ HashMapλ³΄λ€ EnumMapμ μ¬μ©νλ건 μ΄λ¨κΉμ
int bonusBallNumber) { | ||
List<Integer> copyLottoNumbers = new ArrayList<>(lottoNumbers); | ||
copyLottoNumbers.removeAll(winningNumbersLastWeek); | ||
return copyLottoNumbers.contains(bonusBallNumber); |
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.
bonusNumberκ° μ²μλΆν° λΉμ²¨ λ²νΈμ μ€λ³΅λμ§ μλ λ²νΈλΌλ©΄, removeAllμ μννλ©° λ§€λ² λ²νΈλ₯Ό μ κ±°ν νμκ° μμ κ² κ°λ€μ
int matchedCountSum = (int) lottoNumbers.stream() | ||
.filter(winningNumbersLastWeek::contains) | ||
.count(); | ||
MatchedAmount matchedAmount = findByCount(matchedCountSum, isMatchedBonusNumber); | ||
if (matchedAmount.getCount() > 0) { | ||
matchedCountMap.put(matchedAmount, matchedCountMap.get(matchedAmount) + 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.
Stream APIμ groupByλ₯Ό νμ©νλ€λ©΄ μ’ λ κ°λ¨νκ²λ κ°λ₯νλ°, κ³ λ―Όν΄λ³΄λ©΄ μ’μ κ² κ°μ΅λλ€.
@@ -28,7 +29,10 @@ public enum MatchedAmount { | |||
this.amount = amount; | |||
} | |||
|
|||
public static MatchedAmount findByCount(int count) { | |||
public static MatchedAmount findByCount(int count, boolean isMatchedBonus) { // findByNumberWithMatchedBonus | |||
if (count == FIVE.getCount()) { |
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.
μ§κΈμ 보λμ€ λ²νΈ λ§€μΉ μ¬λΆλ§ κ°μ§κ³ λ±κΈ νλ¨μ΄λμμ§λ§, μ΄λ° 쑰건λ€μ΄ κ³μν΄μ μΆκ°λλ€λ©΄ ν΄λΉ λ‘μ§μ κ³μν΄μ νλ¨ λΆκΈ°λ¬Έμ΄ μΆκ°λμΌν κΉμ? λλ€ννμμ νμ©ν΄μ μ΄κ±°νμ μ κ° μΈμ€ν΄μ€κ° μμ μ΄ λ§λμ§ νμ ν μ μλλ‘ ν μ μμκΉμ?
private static final int MAXIMUM_LOTTO_NUMBER_SIZE = 6; | ||
private final 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.
- μμμ λ³μκ°μ κ°νμΌλ‘ κ°λ μ±μ λν보면 μ’μ κ² κ°μ΅λλ€.
- collection νμ μ νλμ΄κΈ°νλ κΆμ₯λ립λλ€.
List<Integer> numbers = IntStream.range(LOTTO_MIN_NUMBER, LOTTO_MAX_NUMBER + 1) | ||
.boxed() | ||
.collect(Collectors.toList()); |
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~45κΉμ§ μμ±ν΄μ 컬λ μ μ λ§λ€κ³ , μκ³ , 6κ°λ₯Ό κΊΌλ΄μ μλ‘μ΄ λ¦¬μ€νΈλ₯Ό λ§λ€μ΄μΌν κΉμ?
- μΌκΈ κ°μ²΄λ₯Ό νμ©ν΄λ³΄λ©΄ μ΄λ¨κΉμ?(μ΄μ νΌλλ°± λ°λ³΅)
- μΊμ±μ νμ©ν΄λ³΄λ©΄ μ΄λ¨κΉμ?
import java.util.Scanner; | ||
import java.util.stream.Collectors; | ||
|
||
import static auto.domain.Lotto.LOTTO_MAX_NUMBER; | ||
import static auto.domain.Lotto.LOTTO_MIN_NUMBER; | ||
|
||
public class InputView { |
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.
λͺ¨λ ν΄λμ€κ° μ μ μ΄λΌλ©΄, μ νΈλ¦¬ν° ν΄λμ€λ‘ λ³Ό μ μλλ°, κ°μ²΄ μμ±μ΄ νμ μλ€λ©΄ κ°μ²΄ μμ±μλͺ»νλλ‘ λ§μ μ μμκΉμ?
μλ νμΈμ 리뷰μ΄λ!
2λ¨κ³ λ λ¨κ²¨μ£Όμ λ¦¬λ·°λ‘ μ½λ μμ±νλ λ μ’μ μ½λκ° λ κ² κ°μ΅λλ€.
μ΄λ²μλ PR 리뷰 λ° μΉμΈ μμ²λ립λλ€.
κ°μ¬ν©λλ€!