本文整理汇总了Java中org.apache.commons.io.comparator.NameFileComparator类的典型用法代码示例。如果您正苦于以下问题:Java NameFileComparator类的具体用法?Java NameFileComparator怎么用?Java NameFileComparator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameFileComparator类属于org.apache.commons.io.comparator包,在下文中一共展示了NameFileComparator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FileAlterationObserver
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
/**
* Construct an observer for the specified directory, file filter and
* file comparator.
*
* @param rootEntry the root directory to observe
* @param fileFilter The file filter or null if none
* @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive
*/
protected FileAlterationObserver(FileEntry rootEntry, FileFilter fileFilter, IOCase caseSensitivity) {
if (rootEntry == null) {
throw new IllegalArgumentException("Root entry is missing");
}
if (rootEntry.getFile() == null) {
throw new IllegalArgumentException("Root directory is missing");
}
this.rootEntry = rootEntry;
this.fileFilter = fileFilter;
if (caseSensitivity == null || caseSensitivity.equals(IOCase.SYSTEM)) {
this.comparator = NameFileComparator.NAME_SYSTEM_COMPARATOR;
} else if (caseSensitivity.equals(IOCase.INSENSITIVE)) {
this.comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR;
} else {
this.comparator = NameFileComparator.NAME_COMPARATOR;
}
}
示例2: getRestorableRealmFiles
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
/**
* Gets a list of currently backed up Realm files, ordered newest to oldest.
* @return List of Realm database files.
*/
@NonNull
public static synchronized File[] getRestorableRealmFiles() {
if (isBackingUp || dbRestoreState != DBRestoreState.NOT) return FileUtils.EMPTY_FILE_ARRAY;
// Get the DB backups directory. If it doesn't exist or isn't a directory, return the empty list.
File dbBackupDir = getExtDir(BACKUP_PATH);
if (!dbBackupDir.isDirectory()) return FileUtils.EMPTY_FILE_ARRAY;
// Get all files whose extensions match our DB backup extension. Sort so that the order is newest to oldest.
File[] restorableDbFiles = dbBackupDir.listFiles((dir, filename) -> {
return filename.endsWith(DB_BACKUP_EXT);
});
Arrays.sort(restorableDbFiles, NameFileComparator.NAME_INSENSITIVE_REVERSE);
return restorableDbFiles;
}
示例3: FileAlterationObserver
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
/**
* Construct an observer for the specified directory, file filter and
* file comparator.
*
* @param rootEntry the root directory to observe
* @param fileFilter The file filter or null if none
* @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive
*/
protected FileAlterationObserver(final FileEntry rootEntry, final FileFilter fileFilter,
final IOCase caseSensitivity) {
if (rootEntry == null) {
throw new IllegalArgumentException("Root entry is missing");
}
if (rootEntry.getFile() == null) {
throw new IllegalArgumentException("Root directory is missing");
}
this.rootEntry = rootEntry;
this.fileFilter = fileFilter;
if (caseSensitivity == null || caseSensitivity.equals(IOCase.SYSTEM)) {
this.comparator = NameFileComparator.NAME_SYSTEM_COMPARATOR;
} else if (caseSensitivity.equals(IOCase.INSENSITIVE)) {
this.comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR;
} else {
this.comparator = NameFileComparator.NAME_COMPARATOR;
}
}
示例4: assertDirectoriesEquals
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
private void assertDirectoriesEquals(File directory1, File directory2, boolean checkFileContents) {
if (directory1.exists()) {
assertTrue(String.format("%s exists but %s does not", directory1, directory2),
directory2.exists());
} else {
assertFalse(String.format("%s does not exists but %s does", directory1, directory2),
directory2.exists());
}
File[] directory1Files = directory1.listFiles();
File[] directory2Files = directory2.listFiles();
// assert directories contain same number of files
assertEquals(String.format("%s has %s files but %s has %s files", directory1.getName(),
directory1Files.length, directory2.getName(), directory2Files.length),
directory1Files.length, directory2Files.length);
// sort files in directory
Arrays.sort(directory1Files, NameFileComparator.NAME_SYSTEM_COMPARATOR);
Arrays.sort(directory2Files, NameFileComparator.NAME_SYSTEM_COMPARATOR);
for (int i = 0; i < directory1Files.length; i++) {
assertFilesEqual(directory1Files[i], directory2Files[i], checkFileContents);
}
}
示例5: FileAlterationObserver
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
/**
* Construct an observer for the specified directory, file filter and
* file comparator.
*
* @param rootEntry the root directory to observe
* @param fileFilter The file filter or null if none
* @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive
*/
protected FileAlterationObserver(FileEntry rootEntry, FileFilter fileFilter, IOCase caseSensitivity, boolean circulate) {
if (rootEntry == null) {
throw new IllegalArgumentException("Root entry is missing");
}
if (rootEntry.getFile() == null) {
throw new IllegalArgumentException("Root directory is missing");
}
this.rootEntry = rootEntry;
this.fileFilter = fileFilter;
this.circulate = circulate;
if (caseSensitivity == null || caseSensitivity.equals(IOCase.SYSTEM)) {
this.comparator = NameFileComparator.NAME_SYSTEM_COMPARATOR;
} else if (caseSensitivity.equals(IOCase.INSENSITIVE)) {
this.comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR;
} else {
this.comparator = NameFileComparator.NAME_COMPARATOR;
}
}
示例6: convertSortOrder
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
protected Comparator<File> convertSortOrder()
{
Comparator<File> result = NameFileComparator.NAME_COMPARATOR;
if ( getSortOrder().equalsIgnoreCase( "NAME_INSENSITIVE_COMPARATOR" ) )
{
result = NameFileComparator.NAME_INSENSITIVE_COMPARATOR;
}
else if ( getSortOrder().equalsIgnoreCase( "NAME_INSENSITIVE_REVERSE" ) )
{
result = NameFileComparator.NAME_INSENSITIVE_REVERSE;
}
else if ( getSortOrder().equalsIgnoreCase( "NAME_REVERSE" ) )
{
result = NameFileComparator.NAME_REVERSE;
}
else if ( getSortOrder().equalsIgnoreCase( "NAME_SYSTEM_COMPARATOR" ) )
{
result = NameFileComparator.NAME_SYSTEM_COMPARATOR;
}
else if ( getSortOrder().equalsIgnoreCase( "NAME_SYSTEM_REVERSE" ) )
{
result = NameFileComparator.NAME_SYSTEM_REVERSE;
}
return result;
}
示例7: cleanDumpDatabase
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
public void cleanDumpDatabase(int keepno)
{
File[]dumps = new File(
cfgManager.getDatabaseConfiguration ().getDumpPath ())
.listFiles(new FilenameFilter()
{
@Override
public boolean accept(File path, String name)
{
if (name.startsWith("dump-"))
return true;
return false;
}
});
if ((dumps!=null) && (dumps.length > keepno))
{
Arrays.sort(dumps, NameFileComparator.NAME_COMPARATOR);
int last = dumps.length - keepno;
for (int index=0; index<last; index++)
{
File dir = dumps[index];
try
{
Date date = new Date (Long.parseLong (dir.getName ()
.replaceAll ("dump-(.*)", "$1")));
LOGGER.info("Cleaned dump of " + date);
FileUtils.deleteDirectory(dir);
}
catch (IOException e)
{
LOGGER.warn("Cannot delete directory " + dir.getPath() + " (" +
e.getMessage() + ")");
}
}
}
}
示例8: getFilesItemsInCurrentDirectory
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
public ArrayList<FileItem> getFilesItemsInCurrentDirectory() {
Operations op = Operations.getInstance(mContext);
Constants.SORT_OPTIONS option = op.getmCurrentSortOption();
Constants.FILTER_OPTIONS filterOption = op.getmCurrentFilterOption();
if (mFileNavigator.getmCurrentNode() == null) mFileNavigator.setmCurrentNode(mFileNavigator.getmRootNode());
File[] files = mFileNavigator.getFilesInCurrentDirectory();
if (files != null) {
mFiles.clear();
Comparator<File> comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR;
switch(option) {
case SIZE:
comparator = SizeFileComparator.SIZE_COMPARATOR;
break;
case LAST_MODIFIED:
comparator = LastModifiedFileComparator.LASTMODIFIED_COMPARATOR;
break;
}
Arrays.sort(files,comparator);
for (int i = 0; i < files.length; i++) {
boolean addToFilter = true;
switch(filterOption) {
case FILES:
addToFilter = !files[i].isDirectory();
break;
case FOLDER:
addToFilter = files[i].isDirectory();
break;
}
if (addToFilter)
mFiles.add(new FileItem(files[i]));
}
}
return mFiles;
}
示例9: getLogNames
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
public List<String> getLogNames() {
List<String> names = new ArrayList<>();
File[] files = this.activityDir.listFiles();
if (files != null) {
Arrays.sort(files, NameFileComparator.NAME_REVERSE);
for (File file : files) {
names.add(file.getName());
}
}
return names;
}
示例10: toTemplates
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
private TemplateFile[] toTemplates(File dir, String parentPath) {
List<TemplateFile> list = new ArrayList<>();
File[] files = dir.listFiles();
Arrays.sort(files, NameFileComparator.NAME_COMPARATOR);
Arrays.sort(files, DirectoryFileComparator.DIRECTORY_COMPARATOR);
for (File file : files) {
TemplateFile templateFile = new TemplateFile();
templateFile.setText(file.getName());
String path = parentPath + "/" + file.getName();
templateFile.setPath(path);
if (file.isDirectory()) {
templateFile.setChildren(toTemplates(file, path));
templateFile.setIconCls("Folder");
} else {
String extension = FilenameUtils.getExtension(file.getName());
if ("html".equals(extension)) {
templateFile.setIconCls("Html");
} else if ("js".equals(extension)) {
templateFile.setIconCls("Script");
} else if ("css".equals(extension)) {
templateFile.setIconCls("Css");
} else {
templateFile.setIconCls("Page");
}
}
list.add(templateFile);
}
return Iterables.toArray(list, TemplateFile.class);
}
示例11: assertOutputsEquals
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
private void assertOutputsEquals(File directory1, File directory2) {
File[] directory1Files = directory1.listFiles();
File[] directory2Files = directory2.listFiles();
// assert directories contain same number of files
assertEquals(String.format("%s has %s files but %s has %s files", directory1.getName(),
directory1Files.length, directory2.getName(), directory2Files.length),
directory1Files.length, directory2Files.length);
// sort files in directory
Arrays.sort(directory1Files, NameFileComparator.NAME_SYSTEM_COMPARATOR);
Arrays.sort(directory2Files, NameFileComparator.NAME_SYSTEM_COMPARATOR);
for (int i = 0; i < directory1Files.length; i++) {
assertFilesEqual(directory1Files[i], directory2Files[i], !directory1Files[i].getName()
.equals(ignorePort));
}
}
示例12: getFilesByExtension
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
public static File[] getFilesByExtension(String path, final String extension) throws IllegalArgumentException {
File pathHandle = new File(path);
if (pathHandle.exists()) {
if (pathHandle.isDirectory()) {
File[] searchResults = pathHandle.listFiles(new FilenameFilter() {
public boolean accept(File folder, String name) {
if (name.toLowerCase().endsWith("." + extension)) {
return true;
} else {
return false;
}
}
});
if (searchResults.length > 0) {
// Sort files by name (Required to load files in a desired order
Arrays.sort(searchResults, NameFileComparator.NAME_INSENSITIVE_COMPARATOR);
}
return searchResults;
} else {
throw new IllegalArgumentException("The given directory path '" + pathHandle.getAbsolutePath() + "' is not a directory.");
}
} else {
throw new IllegalArgumentException("The given directory path '" + pathHandle.getAbsolutePath() + "' does not exist.");
}
}
示例13: open
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
File directory = new File(directoryName);
if(directory.isDirectory()) {
this.files = directory.listFiles((FileFilter) FileFilterUtils.fileFileFilter());
if(files.length > 1) {
Arrays.sort(files, new NameFileComparator());
}
} else {
throw new IllegalArgumentException(directoryName + " is not a directory");
}
currentCount = executionContext.getInt(key, 0);
}
示例14: execute
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
/**
* Called by Maven to run this mojo after parameters have been injected.
*/
public void execute() throws MojoExecutionException {
if (!featuresDirectory.exists()) {
throw new MojoExecutionException("Features directory does not exist");
}
final Collection<File> featureFiles = listFiles(featuresDirectory, new String[] {"feature"}, true);
final List<File> sortedFeatureFiles = new NameFileComparator().sort(new ArrayList<File>(featureFiles));
createOutputDirIfRequired();
File packageDirectory = packageName == null
? outputDirectory
: new File(outputDirectory, packageName.replace('.','/'));
if (!packageDirectory.exists()) {
packageDirectory.mkdirs();
}
final CucumberITGenerator fileGenerator = createFileGenerator();
fileGenerator.generateCucumberITFiles(packageDirectory, sortedFeatureFiles);
getLog().info("Adding " + outputDirectory.getAbsolutePath()
+ " to test-compile source root");
project.addTestCompileSourceRoot(outputDirectory.getAbsolutePath());
}
示例15: setDirectory
import org.apache.commons.io.comparator.NameFileComparator; //导入依赖的package包/类
public void setDirectory(String directory) {
this.files = new File(directory).listFiles((FileFilter) FileFilterUtils.fileFileFilter());
Arrays.sort(files, new NameFileComparator());
}