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 | 0 | public class OlderFirstComparator implements Comparator |
21 | |
{ |
22 | |
public int compare(Object o1, Object o2) |
23 | |
{ |
24 | 0 | if (o1 instanceof File && o2 instanceof File) |
25 | |
{ |
26 | 0 | File f = (File) o1; |
27 | 0 | File f1 = (File) o2; |
28 | 0 | boolean fileNewer = FileUtils.isFileNewer(f, f1); |
29 | 0 | boolean fileOlder = FileUtils.isFileOlder(f, f1); |
30 | 0 | if (!fileNewer && !fileOlder) |
31 | |
{ |
32 | 0 | return 0; |
33 | |
} |
34 | 0 | else if (fileNewer) |
35 | |
{ |
36 | 0 | return 1; |
37 | |
} |
38 | |
else |
39 | |
{ |
40 | 0 | return -1; |
41 | |
} |
42 | |
|
43 | |
} |
44 | 0 | 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 | |
} |