static Set<File> retainAncestors(File... roots){
  if (roots == null) {
    return new HashSet<File>();
  }
  for (int i=0; i < roots.length; i++) {
    for (int j=i + 1; j < roots.length && roots[i] != null; j++) {
      if (roots[j] != null) {
        if (FileUtils.isAncestor(roots[i],roots[j])) {
          roots[j]=null;
        }
 else         if (FileUtils.isAncestor(roots[j],roots[i])) {
          roots[i]=null;
        }
      }
    }
  }
  Set<File> retained=new HashSet<File>(roots.length);
  for (  File file : roots) {
    if (file != null) {
      retained.add(file);
    }
  }
  return retained;
}

static Set < File > retainAncestors ( File ... roots ) { if ( roots == null ) { return new HashSet < File > ( ) ; } for ( int i = 0 ; i < roots . length ; i ++ ) { for ( int j = i + 1 ; j < roots . length && roots [ i ] != null ; j ++ ) { if ( roots [ j ] != null ) { if ( FileUtils . isAncestor ( roots [ i ] , roots [ j ] ) ) { roots [ j ] = null ; } else if ( FileUtils . isAncestor ( roots [ j ] , roots [ i ] ) ) { roots [ i ] = null ; } } } } Set < File > retained = new HashSet < File > ( roots . length ) ; for ( File file : roots ) { if ( file != null ) { retained . add ( file ) ; } } return retained ; }
retains common ancestors and removes subfolders since they will be part of the recursive sharing .
