11package ru .javawebinar .topjava .model ;
22
3- import java . util .Date ;
4- import java . util . EnumSet ;
5- import java .util .Set ;
3+ import org . springframework . util .CollectionUtils ;
4+
5+ import java .util .* ;
66
77import static ru .javawebinar .topjava .util .MealsUtil .DEFAULT_CALORIES_PER_DAY ;
88
@@ -20,17 +20,17 @@ public class User extends AbstractNamedEntity {
2020
2121 private int caloriesPerDay ;
2222
23- public User (Integer id , String name , String email , String password , Role role , Role ... roles ) {
24- this (id , name , email , password , DEFAULT_CALORIES_PER_DAY , true , EnumSet . of ( role , roles ));
23+ public User (Integer id , String name , String email , String password , Role ... roles ) {
24+ this (id , name , email , password , DEFAULT_CALORIES_PER_DAY , true , Arrays . asList ( roles ));
2525 }
2626
27- public User (Integer id , String name , String email , String password , int caloriesPerDay , boolean enabled , Set <Role > roles ) {
27+ public User (Integer id , String name , String email , String password , int caloriesPerDay , boolean enabled , Collection <Role > roles ) {
2828 super (id , name );
2929 this .email = email ;
3030 this .password = password ;
3131 this .caloriesPerDay = caloriesPerDay ;
3232 this .enabled = enabled ;
33- this . roles = roles ;
33+ setRoles ( roles ) ;
3434 }
3535
3636 public String getEmail () {
@@ -73,6 +73,10 @@ public Set<Role> getRoles() {
7373 return roles ;
7474 }
7575
76+ public void setRoles (Collection <Role > roles ) {
77+ this .roles = CollectionUtils .isEmpty (roles ) ? EnumSet .noneOf (Role .class ) : EnumSet .copyOf (roles );
78+ }
79+
7680 public String getPassword () {
7781 return password ;
7882 }
0 commit comments