From 74fab1c53fd3850bf0fd075c93622f14ad8dbe30 Mon Sep 17 00:00:00 2001 From: ulrich Date: Wed, 06 Jan 2021 23:03:51 +0000 Subject: [PATCH] null pruefung hinzugefuegt --- src/java/de/uhilger/filecms/pub/FileDateComparator.java | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/java/de/uhilger/filecms/pub/FileDateComparator.java b/src/java/de/uhilger/filecms/pub/FileDateComparator.java index 2413790..4b0b689 100644 --- a/src/java/de/uhilger/filecms/pub/FileDateComparator.java +++ b/src/java/de/uhilger/filecms/pub/FileDateComparator.java @@ -1,15 +1,13 @@ 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; @@ -26,26 +24,33 @@ 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; } } -- Gitblit v1.9.3