Skip to content

Commit

Permalink
refactor : 구매한 로또들의 당첨 등급을 판별해 저장하는 과정의 로직을 변경
Browse files Browse the repository at this point in the history
Map의 computeIfPresent() 라는 멋있는 메서드를 사용
  • Loading branch information
Gomding committed Feb 25, 2021
1 parent b5b3dd8 commit f962069
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/main/java/lotto/domain/lottos/LottoTickets.java
Expand Up @@ -12,7 +12,6 @@ public class LottoTickets {

public static final String NULL_ERROR_MESSAGE = "null 값은 허용하지 않습니다.";
public static final String EMPTY_ERROR_MESSAGE = "로또는 한장 이상 구매해야 합니다.";
private static final int INCREMENT_COUNT = 1;

private final List<LottoTicket> lottoTickets;

Expand All @@ -25,7 +24,7 @@ public LottoTickets(final List<LottoTicket> lottoTickets) {
public void putLottoResult(Map<LottoRank, Integer> lottoResult, LottoWinner lottoWinner) {
this.lottoTickets.forEach(lottoTicket -> {
LottoRank rank = lottoTicket.getRank(lottoWinner);
lottoResult.put(rank, lottoResult.getOrDefault(rank, 0) + INCREMENT_COUNT);
lottoResult.computeIfPresent(rank, (LottoRank lottoRank, Integer count) -> ++count);
});
}

Expand Down

0 comments on commit f962069

Please sign in to comment.