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
85 lines (67 loc) · 1.98 KB
/
Copy pathUser.java
File metadata and controls
85 lines (67 loc) · 1.98 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
package modern.challenge;
import java.util.Date;
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 UserBuilder getBuilder(String nickname, String password) {
return new User.UserBuilder(nickname, password);
}
public static final class UserBuilder {
private final String nickname;
private final String password;
private final Date created;
private String email;
private String firstname;
private String lastname;
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());
}
}