-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathParticipantName.java
More file actions
40 lines (32 loc) · 1.03 KB
/
ParticipantName.java
File metadata and controls
40 lines (32 loc) · 1.03 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
package nextstep.ladder.domain;
import java.util.Objects;
public class ParticipantName {
private static final int MAX_NAME_LENGTH = 5;
private final String name;
public ParticipantName(String name) {
validateName(name);
this.name = name;
}
public String name() {
return name;
}
private void validateName(String name) {
if(name == null || name.isBlank()) {
throw new IllegalArgumentException("이름은 null이거나 공백일 수 없습니다: " + name);
}
if(name.length() > MAX_NAME_LENGTH) {
throw new IllegalArgumentException("이름의 길이는 5를 초과할 수 없습니다: " + name);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ParticipantName)) return false;
ParticipantName that = (ParticipantName) o;
return Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
}