| | |
| | | package de.uhilger.filecms.pub; |
| | | |
| | | import java.io.File; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * |
| | | * @author ulrich |
| | | */ |
| | | public class FileDateComparator implements Comparator { |
| | | |
| | | private String order; |
| | | public class FileDateComparator extends AbstractComparator { |
| | | |
| | | public FileDateComparator(String order) { |
| | | this.order = order; |
| | |
| | | f2 = (File) obj2; |
| | | } |
| | | if(f1 != null && f2 != null) { |
| | | long l1 = f1.lastModified(); |
| | | long l2 = f2.lastModified(); |
| | | if(order != null && order.equalsIgnoreCase("asc")) { |
| | | if(l1 < l2) { |
| | | 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(l2 > l1) { |
| | | } 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 < l2) { |
| | | if(l1.before(l2)) { |
| | | logger.fine("desc: " + f1.getName() + " groesser " + f2.getName()); |
| | | return 1; |
| | | } else if(l2 > l1) { |
| | | } 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; |
| | | } |
| | | } |