forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
100 lines (78 loc) · 2.49 KB
/
User.java
File metadata and controls
100 lines (78 loc) · 2.49 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package modern.challenge;
import java.util.Date;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
public final class User {
private final String nickname;
private final String password;
private final String firstname;
private final String lastname;
private final String email;
private final Date created;
private User(UserBuilder builder) {
this.nickname = builder.nickname;
this.password = builder.password;
this.created = builder.created;
this.firstname = builder.firstname;
this.lastname = builder.lastname;
this.email = builder.email;
}
public static final class UserBuilder {
@NotNull(message = "cannot be null")
@Size(min = 3, max = 20, message
= "must be between 3 and 20 characters")
private final String nickname;
@NotNull(message = "cannot be null")
@Size(min = 6, max = 50, message
= "must be between 6 and 50 characters")
private final String password;
@Size(min = 3, max = 20, message
= "must be between 3 and 20 characters")
private String firstname;
@Size(min = 3, max = 20, message
= "must be between 3 and 20 characters")
private String lastname;
@Email(message = "must be valid")
private String email;
private final Date created;
public UserBuilder(String nickname, String password) {
this.nickname = nickname;
this.password = password;
this.created = new Date();
}
public UserBuilder firstName(String firsname) {
this.firstname = firsname;
return this;
}
public UserBuilder lastName(String lastname) {
this.lastname = lastname;
return this;
}
public UserBuilder email(String email) {
this.email = email;
return this;
}
public User build() {
return new User(this);
}
}
public String getNickname() {
return nickname;
}
public String getPassword() {
return password;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
public String getEmail() {
return email;
}
public Date getCreated() {
return new Date(created.getTime());
}
}