private static Set<String> removeRedundantPrivileges(Session session,String[] privileges,String[] actions) throws RepositoryException {
  final CqActions cqActions=new CqActions(session);
  final Set<String> cleanedPrivileges=new HashSet<String>();
  if (privileges == null) {
    return cleanedPrivileges;
  }
  cleanedPrivileges.addAll(Arrays.asList(privileges));
  if (actions == null) {
    return cleanedPrivileges;
  }
  for (  final String action : actions) {
    @SuppressWarnings("deprecation") final Set<Privilege> coveredPrivileges=cqActions.getPrivileges(action);
    for (    final Privilege coveredPrivilege : coveredPrivileges) {
      cleanedPrivileges.remove(coveredPrivilege.getName());
    }
  }
  return cleanedPrivileges;
}

private static Set < String > removeRedundantPrivileges ( Session session , String [ ] privileges , String [ ] actions ) throws RepositoryException { final CqActions cqActions = new CqActions ( session ) ; final Set < String > cleanedPrivileges = new HashSet < String > ( ) ; if ( privileges == null ) { return cleanedPrivileges ; } cleanedPrivileges . addAll ( Arrays . asList ( privileges ) ) ; if ( actions == null ) { return cleanedPrivileges ; } for ( final String action : actions ) { @ SuppressWarnings ( "deprecation" ) final Set < Privilege > coveredPrivileges = cqActions . getPrivileges ( action ) ; for ( final Privilege coveredPrivilege : coveredPrivileges ) { cleanedPrivileges . remove ( coveredPrivilege . getName ( ) ) ; } } return cleanedPrivileges ; }
modifies the privileges so that privileges already covered by actions are removed . this is only a best effort operation as one action can lead to privileges on multiple nodes .
