-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLottoResults.java
More file actions
42 lines (33 loc) · 1.11 KB
/
LottoResults.java
File metadata and controls
42 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.javabom.lotto.domain.results;
import com.javabom.lotto.domain.ticket.Money;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class LottoResults {
private final List<LottoResult> lottoResults;
public LottoResults(List<LottoResult> lottoResults) {
this.lottoResults = lottoResults;
}
public List<LottoResult> findResultsOf(LottoResult lottoResult) {
return lottoResults.stream()
.filter(result -> result == lottoResult)
.collect(Collectors.toList());
}
public Money getTotalPrizeMoney() {
long sum = lottoResults.stream()
.mapToLong(LottoResult::getPrize)
.sum();
return new Money(sum);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LottoResults that = (LottoResults) o;
return Objects.equals(lottoResults, that.lottoResults);
}
@Override
public int hashCode() {
return Objects.hash(lottoResults);
}
}