1 package net.sourceforge.importscrubber; 2 3 import java.util.Comparator ; 4 5 public class ImportStatementComparator implements Comparator 6 { 7 private boolean _sortStdLibsHigh; 8 9 public ImportStatementComparator(boolean sortStdLibsHigh) 10 { 11 _sortStdLibsHigh = sortStdLibsHigh; 12 } 13 14 public int compare(Object first, Object second) 15 { 16 if(first == null || second == null ) { 17 throw new IllegalArgumentException ("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 |