1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.start;
20
21 import java.io.File;
22 import java.text.CollationKey;
23 import java.text.Collator;
24 import java.util.Comparator;
25
26
27
28
29 public class FilenameComparator implements Comparator<File>
30 {
31 public static final FilenameComparator INSTANCE = new FilenameComparator();
32 private Collator collator = Collator.getInstance();
33
34 public int compare(File o1, File o2)
35 {
36 if (o1.isFile())
37 {
38 if (o2.isFile())
39 {
40 CollationKey key1 = toKey(o1);
41 CollationKey key2 = toKey(o2);
42 return key1.compareTo(key2);
43 }
44 else
45 {
46
47 return -1;
48 }
49 }
50 else
51 {
52 if (o2.isDirectory())
53 {
54 CollationKey key1 = toKey(o1);
55 CollationKey key2 = toKey(o2);
56 return key1.compareTo(key2);
57 }
58 else
59 {
60
61 return 1;
62 }
63 }
64 }
65
66 private CollationKey toKey(File f)
67 {
68 return collator.getCollationKey(f.getAbsolutePath());
69 }
70 }