-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsers.java
More file actions
46 lines (36 loc) · 987 Bytes
/
Users.java
File metadata and controls
46 lines (36 loc) · 987 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
39
40
41
42
43
44
45
46
package me.day05.practice;
import java.util.Arrays;
import me.day05.practice.exception.DuplicateUserException;
public class Users {
private static final int DEFAULT_CAPACITY = 20;
private static Users users;
private User[] userList;
private Users() {
userList = new User[DEFAULT_CAPACITY];
}
public static Users getInstance() {
if (users == null) {
Users.users = new Users();
}
return Users.users;
}
public User findByUserId(String userId) {
return Arrays.stream(this.userList)
.filter((user -> user.getUserId().equals(userId)))
.findFirst()
.orElse(null);
}
public User copy(User user) throws CloneNotSupportedException {
return (User)(user.clone());
}
public User[] getUserList() {
return userList;
}
public void setUserList(User[] userList) {
this.userList = userList;
}
private boolean isDuplicateUser(User user) {
return Arrays.stream(this.userList)
.anyMatch(users -> users.getUserId().equals(user.getUserId()));
}
}