use of com.mucommander.commons.file.util.FileComparator in project mucommander by mucommander.
the class FileTableModel method getFileRow.
/**
* Returns the index of the row where the given file is located, <code>-1<code> if the file is not in the
* current folder.
*
* @param file the file for which to find the row index
* @return the index of the row where the given file is located, <code>-1<code> if the file is not in the
* current folder
*/
public synchronized int getFileRow(AbstractFile file) {
// Handle parent folder file
if (parent != null && file.equals(parent))
return 0;
// Use dichotomic binary search rather than a dumb linear search since file array is sorted,
// complexity is reduced to O(log n) instead of O(n^2)
int left = parent == null ? 0 : 1;
int right = getRowCount() - 1;
int mid;
AbstractFile midFile;
FileComparator fc = getFileComparator(sortInfo);
while (left <= right) {
mid = (right - left) / 2 + left;
midFile = getCachedFileAtRow(mid);
if (midFile.equals(file))
return mid;
if (fc.compare(file, midFile) < 0)
right = mid - 1;
else
left = mid + 1;
}
return -1;
}
Aggregations