-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathPlayers.java
More file actions
38 lines (29 loc) · 960 Bytes
/
Players.java
File metadata and controls
38 lines (29 loc) · 960 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
36
37
38
package model;
import exception.ExceptionMessage;
import java.util.List;
public class Players {
private static final int MIN_PLAYER_LENGTH = 2;
private final List<Player> players;
public Players(List<String> players) {
validatePlayers(players);
this.players = generatePlayers(players);
}
public int size() {
return players.size();
}
public List<String> getPlayers() {
return players.stream()
.map(Player::getValue)
.toList();
}
private List<Player> generatePlayers(List<String> players) {
return players.stream()
.map(Player::new)
.toList();
}
private void validatePlayers(List<String> players) {
if (players.size() < MIN_PLAYER_LENGTH) {
throw new IllegalArgumentException(ExceptionMessage.MIN_PLAYERS_REQUIRED.getMessage());
}
}
}