-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathParticipants.java
More file actions
53 lines (43 loc) · 1.32 KB
/
Participants.java
File metadata and controls
53 lines (43 loc) · 1.32 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
45
46
47
48
49
50
51
52
53
package nextstep.ladder.domain;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class Participants {
private static final String COMMA = ",";
private final List<ParticipantName> names;
public Participants(String csvNames) {
this(csvNames.split(COMMA));
}
public Participants(String...names) {
this(participantsNames(names));
}
public Participants(List<ParticipantName> names) {
this.names = names;
}
public int size() {
return names.size();
}
public List<String> names() {
return names.stream()
.map(ParticipantName::name)
.collect(Collectors.toUnmodifiableList());
}
private static List<ParticipantName> participantsNames(String[] names) {
return Arrays.stream(names)
.map(String::trim)
.map(ParticipantName::new)
.collect(Collectors.toUnmodifiableList());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Participants)) return false;
Participants that = (Participants) o;
return Objects.equals(names, that.names);
}
@Override
public int hashCode() {
return Objects.hash(names);
}
}