Пример #1
0
 /**
  * Create policy set using the added policy ot policy sets
  *
  * @param policySetDTO policy set element
  * @return String object of the XACML policy Set
  * @throws EntitlementPolicyCreationException throws
  */
 public String createPolicySet(PolicySetDTO policySetDTO)
     throws EntitlementPolicyCreationException {
   try {
     Document doc = createNewDocument();
     if (doc != null) {
       doc.appendChild(PolicyCreatorUtil.createPolicySetElement(policySetDTO, doc));
       StringBuilder policySet = new StringBuilder(PolicyCreatorUtil.getStringFromDocument(doc));
       if (policySetDTO.getPolicies() != null) {
         for (String policy : policySetDTO.getPolicies()) {
           policySet.insert(policySet.indexOf(">") + 1, policy);
         }
       }
       return policySet.toString();
     }
   } catch (EntitlementPolicyCreationException e) {
     throw new EntitlementPolicyCreationException("Error While Creating Policy Set", e);
   }
   return null;
 }
Пример #2
0
  public Doorman() {
    handleInput();
    System.err.println("Max Diff: " + maxDifference + "\nLine: " + clubLine);
    boolean brunoHasControl = true;
    int currentDifference = 0;
    int peopleInClub = 0;
    int numWomen = 0;
    int numMen = 0;
    char firstPersonInLine = clubLine.charAt(0);
    if (firstPersonInLine == WOMAN) numWomen++;
    else numMen++;
    peopleInClub++;
    clubLine = clubLine.substring(1);
    System.err.println("FIRST PERSON CHOSEN + " + clubLine);

    while (brunoHasControl) {
      if (clubLine.length() == 1) {
        firstPersonInLine = clubLine.charAt(0);
        if (firstPersonInLine == WOMAN) numWomen++;
        else numMen++;
        currentDifference = Math.abs(numWomen - numMen);
        if (currentDifference > maxDifference) {
          brunoHasControl = false;
          continue;
        } else {
          peopleInClub++;
          brunoHasControl = false;
          continue;
        }
      }
      firstPersonInLine = clubLine.charAt(0);
      char secondPersonInLine = clubLine.charAt(1);

      if (firstPersonInLine == WOMAN) numWomen++;
      else numMen++;
      currentDifference = Math.abs(numWomen - numMen);
      if (currentDifference > maxDifference) {
        if (firstPersonInLine == WOMAN) numWomen--;
        else numMen--;
        if (secondPersonInLine == WOMAN) numWomen++;
        else numMen++;
        currentDifference = Math.abs(numWomen - numMen);
        if (currentDifference > maxDifference) brunoHasControl = false;
        else {
          peopleInClub++;
          clubLine = clubLine.substring(2);
          StringBuilder sb = new StringBuilder(clubLine);
          sb.insert(0, firstPersonInLine);
          clubLine = sb.toString();
          System.err.println("SECOND PERSON CHOSEN + " + clubLine);
        }
      } else {
        peopleInClub++;
        clubLine = clubLine.substring(1);
        System.err.println("FIRST PERSON CHOSEN + " + clubLine);
      }
      System.err.println("CurrDiff " + currentDifference);
    }

    System.out.println(peopleInClub);
  }