-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathLottoNumber.java
More file actions
44 lines (34 loc) · 1.02 KB
/
LottoNumber.java
File metadata and controls
44 lines (34 loc) · 1.02 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
43
44
package com.nextstep.camp.lotto.domain.vo;
import java.util.Objects;
import com.nextstep.camp.lotto.domain.exception.LottoNumberOutOfRangeException;
public class LottoNumber {
private final int value;
public static final int MIN_VALUE = 1;
public static final int MAX_VALUE = 45;
private LottoNumber(int value) {
validate(value);
this.value = value;
}
private static void validate(int value) {
if (value < MIN_VALUE || value > MAX_VALUE) {
throw new LottoNumberOutOfRangeException();
}
}
public static LottoNumber of(int value) {
return new LottoNumber(value);
}
public int getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LottoNumber that = (LottoNumber) o;
return value == that.value;
}
@Override
public int hashCode() {
return Objects.hashCode(value);
}
}