Skip to content
Snippets Groups Projects
Commit 84eb94f1 authored by ribeaudc's avatar ribeaudc
Browse files

remove: - 'FileComparator' - use one of the Apache commons implementations instead.

SVN: 6299
parent 6cc4b63b
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2007 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.utilities;
import java.io.File;
import java.util.Comparator;
/**
* This class contains <code>Comparator</code> implementation suitable for <code>File</code>.
*
* @author Christian Ribeaud
*/
public final class FileComparator
{
private FileComparator()
{
// This class can not be instantiated.
}
/**
* A {@link File} <code>Comparator</code> implementation that considers value returned by
* {@link File#lastModified()} to sort the files.
*
* @author Christian Ribeaud
*/
public final static Comparator<File> BY_LAST_MODIFIED = new Comparator<File>()
{
//
// Comparator
//
public final int compare(final File o1, final File o2)
{
assert o1 != null && o2 != null;
return (int) (o1.lastModified() - o2.lastModified());
}
};
/**
* A {@link File} <code>Comparator</code> implementation that considers value returned by
* {@link File#getName()} to sort the files.
*
* @author Christian Ribeaud
*/
public final static Comparator<File> BY_NAME = new Comparator<File>()
{
//
// Comparator
//
public final int compare(final File o1, final File o2)
{
assert o1 != null && o2 != null;
return o1.getName().compareTo(o2.getName());
}
};
/**
* A {@link File} <code>Comparator</code> implementation that sorts by type (file or
* directory): first the files are listed then come the directories.
*
* @author Christian Ribeaud
*/
public final static Comparator<File> BY_TYPE = new Comparator<File>()
{
//
// Comparator
//
public final int compare(final File o1, final File o2)
{
assert o1 != null && o2 != null;
return o1.isFile() ? o2.isFile() ? 0 : -1 : +1;
}
};
}
\ No newline at end of file
......@@ -44,6 +44,7 @@ import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.comparator.LastModifiedFileComparator;
import org.apache.commons.lang.CharUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
......@@ -864,9 +865,10 @@ public final class FileUtilities
return paths;
}
public static void sortByLastModified(final File[] files)
@SuppressWarnings("unchecked")
public final static void sortByLastModified(final File[] files)
{
Arrays.sort(files, FileComparator.BY_LAST_MODIFIED);
Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
}
private static void logFailureInDirectoryListing(final RuntimeException exOrNull,
......@@ -1111,6 +1113,7 @@ public final class FileUtilities
*/
public final static String byteCountToDisplaySize(final long size)
{
assert size > -1 : "Negative size value";
final String displaySize;
if (size / FileUtils.ONE_GB > 0)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment