public boolean addPrivilege(Privilege aPrivilege) { boolean wasAdded = false; if (privileges.contains(aPrivilege)) { return false; } if (privileges.contains(aPrivilege)) { return false; } if (privileges.contains(aPrivilege)) { return false; } Employee existingEmployee = aPrivilege.getEmployee(); boolean isNewEmployee = existingEmployee != null && !this.equals(existingEmployee); if (isNewEmployee && existingEmployee.numberOfPrivileges() <= minimumNumberOfPrivileges()) { return wasAdded; } if (isNewEmployee) { aPrivilege.setEmployee(this); } else { privileges.add(aPrivilege); } wasAdded = true; return wasAdded; }
public boolean removePrivilege(Privilege aPrivilege) { boolean wasRemoved = false; // Unable to remove aPrivilege, as it must always have a employee if (this.equals(aPrivilege.getEmployee())) { return wasRemoved; } // employee already at minimum (1) if (numberOfPrivileges() <= minimumNumberOfPrivileges()) { return wasRemoved; } privileges.remove(aPrivilege); wasRemoved = true; return wasRemoved; }