-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathPlayers.java
More file actions
35 lines (27 loc) · 846 Bytes
/
Players.java
File metadata and controls
35 lines (27 loc) · 846 Bytes
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
package nextstep.ladder.domain;
import java.util.List;
import java.util.stream.Collectors;
public class Players {
private final List<Player> players;
private Players(List<Player> players) {
validate(players);
this.players = players;
}
private void validate(List<Player> players) {
if (players == null || players.isEmpty()) {
throw new IllegalArgumentException("참가자가 없습니다.");
}
}
public static Players of(List<String> playerNames) {
List<Player> players = playerNames.stream()
.map(Player::new)
.collect(Collectors.toList());
return new Players(players);
}
public int count() {
return players.size();
}
public Player getPlayer(int index) {
return players.get(index);
}
}