| .. | .. |
|---|
| 88 | 88 | this.password = password; |
|---|
| 89 | 89 | } |
|---|
| 90 | 90 | |
|---|
| 91 | | - public int getRoles() { |
|---|
| 92 | | - return roles; |
|---|
| 91 | + public List<Integer> getRoles() { |
|---|
| 92 | + if (roles == 0) |
|---|
| 93 | + return null; |
|---|
| 94 | + List<Integer> aux = new ArrayList<>(); |
|---|
| 95 | + for (int rol : Rol.ALL) { |
|---|
| 96 | + if ((roles & rol) != 0) // Each rol is a number with only 1 bit == 1 in binary representation |
|---|
| 97 | + aux.add(rol); |
|---|
| 98 | + } |
|---|
| 99 | + return aux; |
|---|
| 93 | 100 | } |
|---|
| 94 | 101 | |
|---|
| 95 | | - public void setRoles(int roles) { |
|---|
| 96 | | - this.roles = roles; |
|---|
| 102 | + public void setRoles(List<Integer> roles) { |
|---|
| 103 | + this.roles = 0; |
|---|
| 104 | + if (roles != null) |
|---|
| 105 | + for (Integer rol : roles) { |
|---|
| 106 | + this.roles |= rol; |
|---|
| 107 | + } |
|---|
| 97 | 108 | } |
|---|
| 98 | 109 | |
|---|
| 99 | 110 | public String getFirstName() { |
|---|
| .. | .. |
|---|
| 181 | 192 | static public class Rol { |
|---|
| 182 | 193 | static public final int ADVANCE = 0x01; |
|---|
| 183 | 194 | static public final int ADMIN = 0x02; |
|---|
| 195 | + static public final int[] ALL = new int[] |
|---|
| 196 | + { ADVANCE, ADMIN }; |
|---|
| 184 | 197 | } |
|---|
| 185 | 198 | |
|---|
| 186 | 199 | } |
|---|