package de.uhilger.filecms.pub; import java.io.File; import java.util.Date; /** * * @author ulrich */ public class FileDateComparator extends AbstractComparator { public FileDateComparator(String order) { this.order = order; } @Override public int compare(Object obj1, Object obj2) { File f1 = null; File f2 = null; if(obj1 instanceof File) { f1 = (File) obj1; } if(obj2 instanceof File) { f2 = (File) obj2; } if(f1 != null && f2 != null) { Date l1 = new Date(f1.lastModified()); Date l2 = new Date(f2.lastModified()); if(order != null && order.equalsIgnoreCase(ORDER_ASC)) { if(l1.before(l2)) { logger.fine("asc: " + f1.getName() + " kleiner " + f2.getName()); return -1; } else if(l1.after(l2)) { logger.fine("asc: " + f1.getName() + " groesser " + f2.getName()); return 1; } else { logger.fine("asc: " + f1.getName() + " gleich " + f2.getName()); return 0; } } else { if(l1.before(l2)) { logger.fine("desc: " + f1.getName() + " groesser " + f2.getName()); return 1; } else if(l1.after(l2)) { logger.fine("desc: " + f1.getName() + " kleiner " + f2.getName()); return -1; } else { logger.fine("desc: " + f1.getName() + " gleich " + f2.getName()); return 0; } } } else { logger.fine("f1 oder f2 null"); return 0; } } }