-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersNameReader.java
More file actions
40 lines (32 loc) · 1.04 KB
/
UsersNameReader.java
File metadata and controls
40 lines (32 loc) · 1.04 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 ladder.domain;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class UsersNameReader {
private final String names;
private UsersNameReader(String names) {
this.validator(names);
this.names = names;
}
public static UsersNameReader newInstace(String names) {
return new UsersNameReader(names);
}
private void validator(String names) {
Optional<String> optNames = Optional.ofNullable(names);
if (optNames.isEmpty()) {
throw new IllegalArgumentException();
}
for (String name : names.split(",")) {
if (name.length() > 5 || name.length() < 1) {
throw new IllegalArgumentException();
}
};
}
public Users convertNamesToUsers() {
List<User> userNames = Arrays.stream(this.names.split(","))
.map(User::newInstance)
.collect(Collectors.toList());
return Users.newInstance(userNames);
}
}