-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #846 from dickschoeller/reduce-complexity
reduce complexity in the old user impl
- Loading branch information
Showing
2 changed files
with
71 additions
and
66 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
gedbrowser-renderer/src/main/java/org/schoellerfamily/gedbrowser/renderer/user/HasRoles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.schoellerfamily.gedbrowser.renderer.user; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.schoellerfamily.gedbrowser.datamodel.users.UserRoleName; | ||
|
||
/** | ||
* @author Dick Schoeller | ||
*/ | ||
public class HasRoles { | ||
/** Logger. */ | ||
private final transient Log logger = LogFactory.getLog(getClass()); | ||
|
||
/** */ | ||
private final Set<UserRoleName> roles = new HashSet<>(); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@SuppressWarnings({ "PMD.OptimizableToArrayCall" }) | ||
public UserRoleName[] getRoles() { | ||
return roles.toArray(new UserRoleName[0]); | ||
} | ||
|
||
/** | ||
* @param role the role to add to the role set | ||
*/ | ||
public void addRole(final UserRoleName role) { | ||
roles.add(role); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public void addRole(final String role) { | ||
try { | ||
roles.add(UserRoleName.valueOf(role)); | ||
} catch (Exception e) { | ||
logger.warn("Tried to add unrecognized role: " + role); | ||
} | ||
} | ||
|
||
/** | ||
* Clear the role set. | ||
*/ | ||
public void clearRoles() { | ||
roles.clear(); | ||
} | ||
|
||
/** | ||
* Check if the user has a particular role. | ||
* | ||
* @param role role that we are looking for | ||
* @return true if the user has the role | ||
*/ | ||
public boolean hasRole(final String role) { | ||
return roles.contains(UserRoleName.valueOf(role)); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public boolean hasRole(final UserRoleName role) { | ||
return roles.contains(role); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters