commit | author | age
|
5410ce
|
1 |
package de.uhilger.filecms.pub; |
U |
2 |
|
|
3 |
import java.io.File; |
17414d
|
4 |
import java.util.Date; |
5410ce
|
5 |
|
U |
6 |
/** |
|
7 |
* |
|
8 |
* @author ulrich |
|
9 |
*/ |
d14d78
|
10 |
public class FileDateComparator extends AbstractComparator { |
5410ce
|
11 |
|
U |
12 |
public FileDateComparator(String order) { |
|
13 |
this.order = order; |
|
14 |
} |
|
15 |
|
|
16 |
@Override |
|
17 |
public int compare(Object obj1, Object obj2) { |
|
18 |
File f1 = null; |
|
19 |
File f2 = null; |
|
20 |
if(obj1 instanceof File) { |
|
21 |
f1 = (File) obj1; |
|
22 |
} |
|
23 |
if(obj2 instanceof File) { |
|
24 |
f2 = (File) obj2; |
|
25 |
} |
|
26 |
if(f1 != null && f2 != null) { |
17414d
|
27 |
Date l1 = new Date(f1.lastModified()); |
U |
28 |
Date l2 = new Date(f2.lastModified()); |
d14d78
|
29 |
if(order != null && order.equalsIgnoreCase(ORDER_ASC)) { |
17414d
|
30 |
if(l1.before(l2)) { |
U |
31 |
logger.fine("asc: " + f1.getName() + " kleiner " + f2.getName()); |
5410ce
|
32 |
return -1; |
17414d
|
33 |
} else if(l1.after(l2)) { |
U |
34 |
logger.fine("asc: " + f1.getName() + " groesser " + f2.getName()); |
5410ce
|
35 |
return 1; |
U |
36 |
} else { |
17414d
|
37 |
logger.fine("asc: " + f1.getName() + " gleich " + f2.getName()); |
5410ce
|
38 |
return 0; |
U |
39 |
} |
|
40 |
} else { |
17414d
|
41 |
if(l1.before(l2)) { |
U |
42 |
logger.fine("desc: " + f1.getName() + " groesser " + f2.getName()); |
5410ce
|
43 |
return 1; |
17414d
|
44 |
} else if(l1.after(l2)) { |
U |
45 |
logger.fine("desc: " + f1.getName() + " kleiner " + f2.getName()); |
5410ce
|
46 |
return -1; |
U |
47 |
} else { |
17414d
|
48 |
logger.fine("desc: " + f1.getName() + " gleich " + f2.getName()); |
5410ce
|
49 |
return 0; |
U |
50 |
} |
|
51 |
} |
|
52 |
} else { |
17414d
|
53 |
logger.fine("f1 oder f2 null"); |
5410ce
|
54 |
return 0; |
U |
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
} |