1
2
3
4
5
6
7 package org.mule.transport.file.comparator;
8
9 import org.mule.util.ClassUtils;
10 import org.mule.util.FileUtils;
11
12 import java.io.File;
13 import java.text.MessageFormat;
14 import java.util.Comparator;
15
16
17
18
19
20 public class OlderFirstComparator implements Comparator
21 {
22 public int compare(Object o1, Object o2)
23 {
24 if (o1 instanceof File && o2 instanceof File)
25 {
26 File f = (File) o1;
27 File f1 = (File) o2;
28 boolean fileNewer = FileUtils.isFileNewer(f, f1);
29 boolean fileOlder = FileUtils.isFileOlder(f, f1);
30 if (!fileNewer && !fileOlder)
31 {
32 return 0;
33 }
34 else if (fileNewer)
35 {
36 return 1;
37 }
38 else
39 {
40 return -1;
41 }
42
43 }
44 throw new IllegalArgumentException(MessageFormat.format(
45 "Expected java.io.File instance, but was {0} and {1}",
46 ClassUtils.getShortClassName(o1, "<null>"),
47 ClassUtils.getShortClassName(o2, "<null")));
48 }
49 }