diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/FileComparator.java b/common/source/java/ch/systemsx/cisd/common/utilities/FileComparator.java deleted file mode 100644 index a350454786f32e7e0896f16955b58120902570a2..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/utilities/FileComparator.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java b/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java index 4dd5603e96823b37d4ccdca748b54a5b70c9effb..c4c4fc300ba857790e820010f97409028030310e 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java @@ -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) {