Java Code Examples for java.io.File.compareTo()

The following are Jave code examples for showing how to use compareTo() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: AbstractCommandTestCase.java   View Source Code Vote up 6 votes
private static Collection<File> sortFiles(Collection<File> files) {

        final class FileComparator implements Comparator<File> {
            public int compare(File f1, File f2) {
                return f1.compareTo(f2);
            }
        }

        if (files.isEmpty()) {
            return Collections.<File>emptyList();
        }
        if (files.size() == 1) {
            return Collections.singletonList(files.iterator().next());
        }

        SortedSet<File> sortedFiles = new TreeSet<File>(new FileComparator());
        sortedFiles.addAll(files);
        return sortedFiles;
    }
 
Example 2
Project: Android-FileBrowser-FilePicker   File: NavigationHelper.java   View Source Code Vote up 5 votes
public boolean navigateBack() {

        File parent = mFileNavigator.getmCurrentNode().getParentFile();
        if(parent==null || parent.compareTo(mFileNavigator.getmCurrentNode())==0 || Constants.externalStorageRoot==null || Constants.externalStorageRoot.compareTo(mFileNavigator.getmCurrentNode())==0 || Constants.internalStorageRoot.compareTo(mFileNavigator.getmCurrentNode())==0)
            return false;
        mFileNavigator.setmCurrentNode(parent);
        triggerFileChanged();
        return true;
    }
 
Example 3
Project: hadoop   File: DirectoryScanner.java   View Source Code Vote up 5 votes
/**
 * Verify whether the actual directory location of block file has the
 * expected directory path computed using its block ID.
 */
private void verifyFileLocation(File actualBlockDir,
    File bpFinalizedDir, long blockId) {
  File blockDir = DatanodeUtil.idToBlockDir(bpFinalizedDir, blockId);
  if (actualBlockDir.compareTo(blockDir) != 0) {
    LOG.warn("Block: " + blockId
        + " has to be upgraded to block ID-based layout");
  }
}
 
Example 4
Project: android-project-gallery   File: FileExplorerActivity.java   View Source Code Vote up 5 votes
public int compare(File left, File right)
{
	if (left.isDirectory())
	{
		if (right.isDirectory())
		{
			return left.compareTo(right);
		}

		return -1;
	}

	return right.isDirectory() ? 1 : left.compareTo(right);
}
 
Example 5
Project: markor   File: FilesystemListFragment.java   View Source Code Vote up 4 votes
public void sortAdapter() {
    final int sortMethod = AppSettings.get().getSortMethod();
    final boolean sortReverse = AppSettings.get().isSortReverse();
    int count = _filesCurrentlyShown.size();
    int lastFolderIndex = 0;
    for (int i = 0; i < count; i++) {
        if (_filesCurrentlyShown.get(i).isDirectory()) {
            lastFolderIndex++;
        }
    }

    Comparator<File> comparator = new Comparator<File>() {
        @Override
        public int compare(File file, File other) {
            if (sortReverse) {
                File swap = file;
                file = other;
                other = swap;
            }

            switch (sortMethod) {
                case SORT_BY_NAME:
                    return new File(file.getAbsolutePath().toLowerCase()).compareTo(
                            new File(other.getAbsolutePath().toLowerCase()));
                case SORT_BY_DATE:
                    return Long.valueOf(other.lastModified()).compareTo(file.lastModified());
                case SORT_BY_FILESIZE:
                    if (file.isDirectory() && other.isDirectory()) {
                        return other.list().length - file.list().length;
                    }
                    return Long.valueOf(other.length()).compareTo(file.length());
            }
            return file.compareTo(other);
        }
    };

    Collections.sort(_filesCurrentlyShown.subList(0, lastFolderIndex), comparator);
    Collections.sort(_filesCurrentlyShown.subList(lastFolderIndex, count), comparator);

    reloadAdapter();
}
 
Example 6
Project: android-project-gallery   File: FileExplorerActivity.java   View Source Code Vote up 4 votes
public int compare(File left, File right)
{
	return left.compareTo(right);
}
 
Example 7
Project: Moenagade   File: DefaultFileComparator.java   View Source Code Vote up 2 votes
/**
 * Compare the two files using the {@link File#compareTo(File)} method.
 * 
 * @param file1 The first file to compare
 * @param file2 The second file to compare
 * @return the result of calling file1's
 * {@link File#compareTo(File)} with file2 as the parameter.
 */
public int compare(File file1, File file2) {
    return file1.compareTo(file2);
}
 
Example 8
Project: lams   File: DefaultFileComparator.java   View Source Code Vote up 2 votes
/**
 * Compare the two files using the {@link File#compareTo(File)} method.
 * 
 * @param file1 The first file to compare
 * @param file2 The second file to compare
 * @return the result of calling file1's
 * {@link File#compareTo(File)} with file2 as the parameter.
 */
public int compare(File file1, File file2) {
    return file1.compareTo(file2);
}