/**
  * Test if there is an intersection between the two arrays of privileges
  *
  * @param privileges1
  * @param privileges2
  * @return whether the two arrays contain any common element
  */
 private static boolean areIntersecting(Privilege[] privileges1, List<Privilege> privileges2) {
   for (Privilege privilege1 : privileges1) {
     if (privileges2.contains(privilege1)) {
       return true;
     }
   }
   return false;
 }
 public String[] getLockTokens() {
   List<String> allTokens = new ArrayList<String>(tokens);
   for (Session session : sessions.values()) {
     String[] tokens = session.getLockTokens();
     for (String token : tokens) {
       if (!allTokens.contains(token)) {
         allTokens.add(token);
       }
     }
   }
   return allTokens.toArray(new String[allTokens.size()]);
 }
  private static Privilege[] filterPrivileges(
      Privilege[] privileges, List<Privilege> privilegesToFilterOut) {

    Set<Privilege> filteredResult = new HashSet<Privilege>();
    for (Privilege privilege : privileges) {
      if (!privilegesToFilterOut.contains(privilege)) {
        if (privilege.isAggregate()
            && areIntersecting(privilege.getDeclaredAggregatePrivileges(), privilegesToFilterOut)) {
          // We de-aggregate a privilege in case any of its children are to be filtered out, since a
          // privilege is valid only if all its children are valid.
          filteredResult.addAll(
              Arrays.asList(
                  filterPrivileges(
                      privilege.getDeclaredAggregatePrivileges(), privilegesToFilterOut)));
        } else {
          filteredResult.add(privilege);
        }
      }
    }

    return filteredResult.toArray(new Privilege[filteredResult.size()]);
  }