|
| 1 | +package ru.javawebinar.topjava.model; |
| 2 | + |
| 3 | +import java.util.Date; |
| 4 | +import java.util.EnumSet; |
| 5 | +import java.util.Set; |
| 6 | + |
| 7 | +/** |
| 8 | + * User: gkislin |
| 9 | + * Date: 22.08.2014 |
| 10 | + */ |
| 11 | +public class User extends NamedEntity { |
| 12 | + |
| 13 | + private static final int DEFAULT_CALORIES_PER_DAY = 2000; |
| 14 | + |
| 15 | + protected String email; |
| 16 | + |
| 17 | + protected String password; |
| 18 | + |
| 19 | + protected boolean enabled = true; |
| 20 | + |
| 21 | + protected Date registered = new Date(); |
| 22 | + |
| 23 | + protected Set<Role> roles; |
| 24 | + |
| 25 | + protected int caloriesPerDay = DEFAULT_CALORIES_PER_DAY; |
| 26 | + |
| 27 | + public User() { |
| 28 | + } |
| 29 | + |
| 30 | + public User(Integer id, String name, String email, String password, Role role, Role... roles) { |
| 31 | + this(id, name, email, password, DEFAULT_CALORIES_PER_DAY, true, EnumSet.of(role, roles)); |
| 32 | + } |
| 33 | + |
| 34 | + public User(Integer id, String name, String email, String password, int caloriesPerDay, boolean enabled, Set<Role> roles) { |
| 35 | + super(id, name); |
| 36 | + this.email = email; |
| 37 | + this.password = password; |
| 38 | + this.caloriesPerDay = caloriesPerDay; |
| 39 | + this.enabled = enabled; |
| 40 | + this.roles = roles; |
| 41 | + } |
| 42 | + |
| 43 | + public String getEmail() { |
| 44 | + return email; |
| 45 | + } |
| 46 | + |
| 47 | + public void setEmail(String email) { |
| 48 | + this.email = email; |
| 49 | + } |
| 50 | + |
| 51 | + public void setPassword(String password) { |
| 52 | + this.password = password; |
| 53 | + } |
| 54 | + |
| 55 | + public Date getRegistered() { |
| 56 | + return registered; |
| 57 | + } |
| 58 | + |
| 59 | + public void setRegistered(Date registered) { |
| 60 | + this.registered = registered; |
| 61 | + } |
| 62 | + |
| 63 | + public void setEnabled(boolean enabled) { |
| 64 | + this.enabled = enabled; |
| 65 | + } |
| 66 | + |
| 67 | + public int getCaloriesPerDay() { |
| 68 | + return caloriesPerDay; |
| 69 | + } |
| 70 | + |
| 71 | + public void setCaloriesPerDay(int caloriesPerDay) { |
| 72 | + this.caloriesPerDay = caloriesPerDay; |
| 73 | + } |
| 74 | + |
| 75 | + public boolean isEnabled() { |
| 76 | + return enabled; |
| 77 | + } |
| 78 | + |
| 79 | + public Set<Role> getRoles() { |
| 80 | + return roles; |
| 81 | + } |
| 82 | + |
| 83 | + public String getPassword() { |
| 84 | + return password; |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public String toString() { |
| 89 | + return "User (" + |
| 90 | + "id=" + id + |
| 91 | + ", email=" + email + |
| 92 | + ", name=" + name + |
| 93 | + ", enabled=" + enabled + |
| 94 | + ", roles=" + roles + |
| 95 | + ", caloriesPerDay=" + caloriesPerDay + |
| 96 | + ')'; |
| 97 | + } |
| 98 | +} |
0 commit comments