Beispiel #1
1
  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;
  }
Beispiel #2
0
  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;
  }