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