当前位置: 首页>>代码示例>>Java>>正文


Java File.compareTo方法代码示例

本文整理汇总了Java中java.io.File.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java File.compareTo方法的具体用法?Java File.compareTo怎么用?Java File.compareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.compareTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sortFiles

import java.io.File; //导入方法依赖的package包/类
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;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:AbstractCommandTestCase.java

示例2: navigateBack

import java.io.File; //导入方法依赖的package包/类
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;
    }
 
开发者ID:adityak368,项目名称:Android-FileBrowser-FilePicker,代码行数:10,代码来源:NavigationHelper.java

示例3: verifyFileLocation

import java.io.File; //导入方法依赖的package包/类
/**
 * 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");
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:DirectoryScanner.java

示例4: compare

import java.io.File; //导入方法依赖的package包/类
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);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:15,代码来源:FileExplorerActivity.java

示例5: sortAdapter

import java.io.File; //导入方法依赖的package包/类
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();
}
 
开发者ID:gsantner,项目名称:markor,代码行数:42,代码来源:FilesystemListFragment.java

示例6: compare

import java.io.File; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:12,代码来源:DefaultFileComparator.java


注:本文中的java.io.File.compareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。