-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.java
35 lines (25 loc) · 810 Bytes
/
User.java
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 behavioral.mediator;
import java.util.ArrayList;
import java.util.List;
public class User {
private String username;
private String password;
private User(String username, String password) {
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
private final static List<User> users = new ArrayList<>();
static {
users.add(new User("alice", "123"));
users.add(new User("michael", "456"));
}
public static User getUser(String username) {
return users.stream().filter(user -> user.getUsername().equals(username)).findFirst().orElseGet(null);
}
public boolean isPasswordValid(String password) {
return this.password.equals(password);
}
}