}
public class WeblogResourceComparator implements Comparator {
public int compare(Object o1, Object o2) {
WeblogResource r1 = (WeblogResource)o1;
WeblogResource r2 = (WeblogResource)o2;
// consider directories so they go to the top of the list
if(r1.isDirectory() && r2.isDirectory()) {
// if we have 2 directories then just go by name
return r1.getPath().compareTo(r2.getPath());
} else if(r1.isDirectory()) {
// directories go before files
return -1;
} else if(r2.isDirectory()) {
// directories go before files
return 1;
} else {
// if we have 2 files then just go by name
return r1.getPath().compareTo(r2.getPath());
}
}