public static List<VirtualFile> findFilesClosestToTarget(@NotNull final List<String> targetParentFolders,final List<FileInfo> candidates,final int minProximityThreshold){
  if (candidates.isEmpty()) {
    return Collections.emptyList();
  }
  for (  String folderName : targetParentFolders) {
    for (    FileInfo info : candidates) {
      info.processRelativePathComponent(folderName);
    }
  }
  int maxProximity=0;
  for (  FileInfo fileInfo : candidates) {
    final int proximity=fileInfo.getProximity();
    if (proximity > maxProximity) {
      maxProximity=proximity;
    }
  }
  if (maxProximity >= minProximityThreshold) {
    final List<VirtualFile> files=new ArrayList<VirtualFile>();
    for (    FileInfo info : candidates) {
      if (info.getProximity() == maxProximity) {
        files.add(info.getFile());
      }
    }
    return files;
  }
  return Collections.emptyList();
}

public static List < VirtualFile > findFilesClosestToTarget ( @ NotNull final List < String > targetParentFolders , final List < FileInfo > candidates , final int minProximityThreshold ) { if ( candidates . isEmpty ( ) ) { return Collections . emptyList ( ) ; } for ( String folderName : targetParentFolders ) { for ( FileInfo info : candidates ) { info . processRelativePathComponent ( folderName ) ; } } int maxProximity = 0 ; for ( FileInfo fileInfo : candidates ) { final int proximity = fileInfo . getProximity ( ) ; if ( proximity > maxProximity ) { maxProximity = proximity ; } } if ( maxProximity >= minProximityThreshold ) { final List < VirtualFile > files = new ArrayList < VirtualFile > ( ) ; for ( FileInfo info : candidates ) { if ( info . getProximity ( ) == maxProximity ) { files . add ( info . getFile ( ) ) ; } } return files ; } return Collections . emptyList ( ) ; }
looks for files with given name which are close to given path
