當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。