本文整理汇总了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;
}
示例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;
}
示例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");
}
}
示例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);
}
示例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();
}
示例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);
}