package org.splat.service.dto;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
/**
- * Role DTO.
+ * DTO for keeping roles of a user.
*
* @see UserDTO
*/
public class RoleDTO {
- private String username;
- private String role;
+ /**
+ * User name.
+ */
+ private transient String _username;
+ /**
+ * Roles names.
+ */
+ private String _name;
// ==============================================================================================================================
// Constructors
// ==============================================================================================================================
- // Database fetch constructor
+ /**
+ * Bean replication constructor.
+ */
protected RoleDTO() {
+ // Bean replication constructor
}
- // Initialization constructor
- protected RoleDTO(String username, String role) {
- this.username = username;
- this.role = role;
+ /**
+ * Initialization constructor.
+ * @param username user name
+ * @param role role name
+ */
+ protected RoleDTO(final String username, final String role) {
+ this._username = username;
+ this._name = role;
}
// ==============================================================================================================================
// Protected member functions
// ==============================================================================================================================
- protected void addRole(String role) {
- this.role = this.role + "," + role;
+ /**
+ * Add a role.
+ * @param role the role to add
+ */
+ protected void addRole(final String role) {
+ this._name = this._name + "," + role;
}
+ /**
+ * Get roles as an array of separate DTOs.
+ * @return array of roles
+ */
protected RoleDTO[] toArray() {
- String[] name = role.split(",");
- Vector<RoleDTO> role = new Vector<RoleDTO>();
+ String[] name = _name.split(",");
+ List<RoleDTO> role = new ArrayList<RoleDTO>();
- for (int i = 0; i < name.length; i++)
- role.add(new RoleDTO(username, name[i]));
+ for (int i = 0; i < name.length; i++) {
+ role.add(new RoleDTO(_username, name[i]));
+ }
return role.toArray(new RoleDTO[name.length]);
}
// In functions below, the role is supposed having previously been extracted as an array.
public String getName() {
- return role;
+ return _name;
}
public void setName(final String name) {
- role = name;
+ _name = name;
}
- public boolean is(String name) {
- return this.role.equals(name);
+ public boolean is(final String name) {
+ return this._name.equals(name);
}
- public boolean isSame(RoleDTO other) {
- return this.role.equals(other.role);
+ public boolean isSame(final RoleDTO other) {
+ return this._name.equals(other._name);
}
}
\ No newline at end of file