diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/DirectoryScanningTimerTask.java b/common/source/java/ch/systemsx/cisd/common/utilities/DirectoryScanningTimerTask.java index 51545773333c599c9d0190afbb9550c4b18f8bdd..dbe2c31c677ceb6dd2531264de532dcd2f643c3e 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/DirectoryScanningTimerTask.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/DirectoryScanningTimerTask.java @@ -19,7 +19,6 @@ package ch.systemsx.cisd.common.utilities; import java.io.File; import java.io.FileFilter; import java.util.Arrays; -import java.util.Comparator; import java.util.HashSet; import java.util.Set; import java.util.TimerTask; @@ -126,15 +125,10 @@ public final class DirectoryScanningTimerTask extends TimerTask implements ISelf { return; } - // Sort in order of "oldest first" in order to move older items before newer items. This becomes important when + // Sort in order of "oldest first" in order to move older items before newer items. This becomes important + // when // doing online quality control of measurements. - Arrays.sort(paths, new Comparator<File>() - { - public int compare(File o1, File o2) - { - return (int) (o1.lastModified() - o2.lastModified()); - } - }); + Arrays.sort(paths, FileComparator.BY_LAST_MODIFIED); for (File path : paths) { if (faultyPathsFile.equals(path)) // Never touch the faultyPathsFile. @@ -204,6 +198,8 @@ public final class DirectoryScanningTimerTask extends TimerTask implements ISelf { if (ex == null) { + // TODO 2007-06-22, Christian Ribeaud: This part belongs to 'check' method, does not it? Actually we already + // check if we get a directory in the 'check' method. Or maybe we want to be paranoiac? if (sourceDirectory.isFile()) { notificationLog.error(String diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/FileComparator.java b/common/source/java/ch/systemsx/cisd/common/utilities/FileComparator.java new file mode 100644 index 0000000000000000000000000000000000000000..5e8a56c21f4958659b22e19718de7491fe0bba9f --- /dev/null +++ b/common/source/java/ch/systemsx/cisd/common/utilities/FileComparator.java @@ -0,0 +1,70 @@ +/* + * 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 int compare(File o1, File o2) + { + 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 int compare(File o1, File o2) + { + return o1.getName().compareTo(o2.getName()); + } + }; +} \ No newline at end of file