com.bazaarvoice.commons.data.model.AbstractRoleAndRightBasedUser Maven / Gradle / Ivy
package com.bazaarvoice.commons.data.model;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
public class AbstractRoleAndRightBasedUser, L extends RightBasedRole, R extends UserRight> extends AbstractRoleBasedUser
implements RightBasedRoleBasedUser {
@Override
public boolean hasRight(R right) {
return hasRight(Collections.singletonList(right));
}
@Override
public boolean hasRight(R... rights) {
return hasRight(Arrays.asList(rights));
}
@Override
public boolean hasRight(Collection extends R> rights) {
Set roles = getRoles();
if (roles == null) {
return false;
}
for (L role : roles) {
Set roleRights = role.getRights();
for (R right : rights) {
if (roleRights.contains(right)) {
return true;
}
}
}
return false;
}
@Override
public boolean hasAllRights(R... rights) {
return hasAllRights(Arrays.asList(rights));
}
@Override
public boolean hasAllRights(Collection rights) {
for(R r : rights){
if(!hasRight(r)){
return false;
}
}
return true;
}
}