java.io.File.compareTo()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中java.io.File.compareTo()方法的一些代码示例,展示了File.compareTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.compareTo()方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:compareTo

File.compareTo介绍

[英]Returns the relative sort ordering of the paths for this file and the file another. The ordering is platform dependent.
[中]返回此文件和另一个文件路径的相对排序顺序。订购取决于平台。

代码示例

代码示例来源:origin: commons-io/commons-io

/**
   * 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.
   */
  @Override
  public int compare(final File file1, final File file2) {
    return file1.compareTo(file2);
  }
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

@Override
  public Comparator<File> getComparator() {
    return (a, b) -> a.compareTo(b);
  }
},

代码示例来源:origin: sleekbyte/tailor

@Override
public int compareTo(Printer printer) {
  return this.inputFile.compareTo(printer.inputFile);
}

代码示例来源:origin: docker-java/docker-java

private boolean isBaseDirectory(File directory) {
  return directory.compareTo(baseDirectory) == 0;
}

代码示例来源:origin: apache/incubator-druid

@Override
 public int compare(File o1, File o2)
 {
  try {
   return Ints.compare(Integer.parseInt(o1.getName()), Integer.parseInt(o2.getName()));
  }
  catch (NumberFormatException e) {
   log.error(e, "Couldn't compare as numbers? [%s][%s]", o1, o2);
   return o1.compareTo(o2);
  }
 }
}

代码示例来源:origin: plantuml/plantuml

public int compareTo(GeneratedImage this2) {
  final int cmp = this.pngFile.compareTo(this2.getPngFile());
  if (cmp != 0) {
    return cmp;
  }
  return this.description.compareTo(this2.getDescription());
}

代码示例来源:origin: jeremylong/DependencyCheck

File mpp = new File(project.getBasedir(), m);
mpp = mpp.getCanonicalFile();
if (mpp.compareTo(mod.getBasedir()) == 0 && descendants.add(mod)
    && getLog().isDebugEnabled()) {
  getLog().debug(String.format("Descendant module %s added", mod.getName()));
    File mpp = new File(dec.getBasedir(), mod);
    mpp = mpp.getCanonicalFile();
    if (mpp.compareTo(p.getBasedir()) == 0) {
      addedDescendants.add(p);

代码示例来源:origin: voldemort/voldemort

+ " does not exist.");
if(!(newVersionDir.getParentFile().compareTo(storeDir.getAbsoluteFile()) == 0 && ReadOnlyUtils.checkVersionDirName(newVersionDir)))
  throw new VoldemortException("Invalid version folder name '"
                 + newVersionDir

代码示例来源:origin: facebook/facebook-android-sdk

@Override
public int compareTo(ModifiedFile another) {
  if (getModified() < another.getModified()) {
    return -1;
  } else if (getModified() > another.getModified()) {
    return 1;
  } else {
    return getFile().compareTo(another.getFile());
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg("file"))
public Memory compareTo(Environment env, Memory... args){
  File what;
  if (args[0].isObject()){
    if (args[0].instanceOf("php\\io\\File")){
      FileObject fileObject = (FileObject)args[0].toValue(ObjectMemory.class).value;
      what = fileObject.file;
    } else {
      exception(env, "Argument 1 must be an instance of %s", "php\\io\\File");
      return Memory.FALSE;
    }
  } else {
    what = new File(args[0].toString());
  }
  return LongMemory.valueOf(file.compareTo(what));
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Compare this FileResource to another Resource.
 * @param another the other Resource against which to compare.
 * @return a negative integer, zero, or a positive integer as this FileResource
 *         is less than, equal to, or greater than the specified Resource.
 */
@Override
public int compareTo(Resource another) {
  if (isReference()) {
    return getCheckedRef().compareTo(another);
  }
  if (this.equals(another)) {
    return 0;
  }
  FileProvider otherFP = another.as(FileProvider.class);
  if (otherFP != null) {
    File f = getFile();
    if (f == null) {
      return -1;
    }
    File of = otherFP.getFile();
    if (of == null) {
      return 1;
    }
    int compareFiles = f.compareTo(of);
    return compareFiles != 0 ? compareFiles
      : getName().compareTo(another.getName());
  }
  return super.compareTo(another);
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

/**
 * Verify whether the actual directory location of block file has the
 * expected directory path computed using its block ID.
 */
private void verifyFileLocation(File actualBlockFile,
  File bpFinalizedDir, long blockId) {
 File expectedBlockDir =
   DatanodeUtil.idToBlockDir(bpFinalizedDir, blockId);
 File actualBlockDir = actualBlockFile.getParentFile();
 if (actualBlockDir.compareTo(expectedBlockDir) != 0) {
  LOG.warn("Block: " + blockId +
    " found in invalid directory.  Expected directory: " +
    expectedBlockDir + ".  Actual directory: " + actualBlockDir);
 }
}

代码示例来源:origin: geotools/geotools

/** Just groups together files that have the same ShpFiles instance */
public int compareTo(StorageFile o) {
  // group togheter files that have the same shpefile instance
  if (this == o) {
    return 0;
  }
  // assume two StorageFile that do not share the same ShpFiles
  // are not given the same temp file
  return getFile().compareTo(o.getFile());
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

@Override
public int compareWith(ScanInfo info) {
 return info.getBlockFile().compareTo(getBlockFile());
}

代码示例来源:origin: spring-projects/spring-roo

public int compareTo(final FileDetails o) {
 if (o == null) {
  throw new NullPointerException();
 }
 // N.B. this is in reverse order to how we'd normally compare
 int result = o.getFile().compareTo(file);
 if (result == 0) {
  result = ObjectUtils.compare(o.getLastModified(), lastModified);
 }
 return result;
}

代码示例来源:origin: pippo-java/pippo

@Override
public int compare(DirEntry o1, DirEntry o2) {
  if (o1.isDirectory() && !o2.isDirectory()) {
    return -1;
  }
  if (!o1.isDirectory() && o2.isDirectory()) {
    return 1;
  }
  return o1.file.compareTo(o2.file);
}

代码示例来源:origin: Hive2Hive/Hive2Hive

@Override
  public int compare(File file1, File file2) {
    return file1.compareTo(file2);
  }
});

代码示例来源:origin: org.tmatesoft.svnkit/svnkit

public int compareTo(Object obj) {
  if (obj == null || obj.getClass() != MergePath.class) {
    return -1;
  }
  MergePath mergePath = (MergePath) obj; 
  if (this == mergePath) {
    return 0;
  }
  return myPath.compareTo(mergePath.myPath);
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

if (!diskMetaFileExists) {
 LOG.warn(warningPrefix + "null");
} else if (memMetaFile.compareTo(diskMetaFile) != 0) {
 LOG.warn(warningPrefix + diskMetaFile.getAbsolutePath());

代码示例来源:origin: freenet/fred

@Override
public int compareTo(Dependency arg0) {
  if(this == arg0) return 0;
  if(order > arg0.order) return 1;
  else if(order < arg0.order) return -1;
  // Filename comparisons aren't very reliable (e.g. "./test" versus "test" are not equals()!), go by getName() first.
  int ret = newFilename.getName().compareTo(arg0.newFilename.getName());
  if(ret != 0) return ret;
  return newFilename.compareTo(arg0.newFilename);
}

相关文章