1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.transport.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 | 2 | public class OlderFirstComparator implements Comparator |
24 | |
{ |
25 | |
public int compare(Object o1, Object o2) |
26 | |
{ |
27 | 2 | if (o1 instanceof File && o2 instanceof File) |
28 | |
{ |
29 | 2 | File f = (File) o1; |
30 | 2 | File f1 = (File) o2; |
31 | 2 | boolean fileNewer = FileUtils.isFileNewer(f, f1); |
32 | 2 | boolean fileOlder = FileUtils.isFileOlder(f, f1); |
33 | 2 | if (!fileNewer && !fileOlder) |
34 | |
{ |
35 | 0 | return 0; |
36 | |
} |
37 | 2 | else if (fileNewer) |
38 | |
{ |
39 | 2 | return 1; |
40 | |
} |
41 | |
else |
42 | |
{ |
43 | 0 | return -1; |
44 | |
} |
45 | |
|
46 | |
} |
47 | 0 | 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 | |
} |