KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > importscrubber > ImportStatementComparator


1 package net.sourceforge.importscrubber;
2
3 import java.util.Comparator JavaDoc;
4
5 public class ImportStatementComparator implements Comparator JavaDoc
6 {
7     private boolean _sortStdLibsHigh;
8
9     public ImportStatementComparator(boolean sortStdLibsHigh)
10     {
11         _sortStdLibsHigh = sortStdLibsHigh;
12     }
13
14     public int compare(Object JavaDoc first, Object JavaDoc second)
15     {
16         if(first == null || second == null ) {
17             throw new IllegalArgumentException JavaDoc("Either " + first + " or " + second + " is null");
18         }
19
20         ImportStatement firstImport = (ImportStatement)first;
21         ImportStatement secondImport = (ImportStatement)second;
22
23         if (_sortStdLibsHigh) {
24             if (firstImport.isInStdJavaLibrary() && !secondImport.isInStdJavaLibrary()) {
25                 return -1;
26             }
27
28             if (!firstImport.isInStdJavaLibrary() && secondImport.isInStdJavaLibrary()) {
29                 return 1;
30             }
31
32             if (firstImport.isInStdJavaExtensionLibrary() && !secondImport.isInStdJavaExtensionLibrary()) {
33                 return -1;
34             }
35
36             if (!firstImport.isInStdJavaExtensionLibrary() && secondImport.isInStdJavaExtensionLibrary()) {
37                 return 1;
38             }
39         }
40
41         return firstImport.compareTo(secondImport);
42     }
43 }
44
45
Popular Tags