public static File[] findKthVersionedDir(File[] versionDirs, int start, int end) {
        if(start < 0 || end >= versionDirs.length) {
            logger.error("Incorrect version number requested (" + start + "," + end
                         + "). Should be between (0," + (versionDirs.length - 1) + ")");
            return null;
        }
        Collections.sort(Arrays.asList(versionDirs), new Comparator<File>() {

            public int compare(File file1, File file2) {
                long fileId1 = getVersionId(file1), fileId2 = getVersionId(file2);
                if(fileId1 == fileId2) {
                    return 0;
                } else {
                    if(fileId1 == -1) {
                        return 1;
                    }
                    if(fileId2 == -1) {
                        return -1;
                    }
                    if(fileId1 < fileId2) {
                        return -1;
                    } else {
                        return 1;
                    }
                }

            }
        });

        File[] returnedFiles = new File[end - start + 1];
        for(int index = start, index2 = 0; index <= end; index++, index2++) {
            returnedFiles[index2] = versionDirs[index];
        }
        return returnedFiles;
    }
public static File [ ] findKthVersionedDir ( File [ ] versionDirs , int start , int end ) { if ( start < 0 || end >= versionDirs . length ) { logger . error ( "Incorrect version number requested (" + start + "," + end + "). Should be between (0," + ( versionDirs . length - 1 ) + ")" ) ; return null ; } Collections . sort ( Arrays . asList ( versionDirs ) , new Comparator < File > ( ) { public int compare ( File file1 , File file2 ) { long fileId1 = getVersionId ( file1 ) , fileId2 = getVersionId ( file2 ) ; if ( fileId1 == fileId2 ) { return 0 ; } else { if ( fileId1 == - 1 ) { return 1 ; } if ( fileId2 == - 1 ) { return - 1 ; } if ( fileId1 < fileId2 ) { return - 1 ; } else { return 1 ; } } } } ) ; File [ ] returnedFiles = new File [ end - start + 1 ] ; for ( int index = start , index2 = 0 ; index <= end ; index ++ , index2 ++ ) { returnedFiles [ index2 ] = versionDirs [ index ] ; } return returnedFiles ; }
Returns the directories sorted and indexed between [start, end] where
start >= 0 and end < len(files)
<p>
TODO: Can be made better using 'selection algorithm'
<p>

@param versionDirs The list of files to search in
@param start Starting index
@param end End index
@return Array of files