1 6 7 package com.sun.japex.report; 8 9 import java.io.File ; 10 import java.util.Comparator ; 11 import java.util.Date ; 12 13 14 public class DateComparator implements Comparator { 15 public static final int ORDER_DESC = 1; 16 public static final int ORDER_ASC = 2; 17 private int order; 18 19 public DateComparator() { 20 order = ORDER_DESC; 21 } 22 public DateComparator(int order) { 23 this.order = order; 24 } 25 public int compare(Object o1, Object o2) { 26 if ( (o1 instanceof File ) && (o2 instanceof File ) ) 27 { 28 long lm1 = ((File )o1).lastModified(); 29 long lm2 = ((File )o2).lastModified(); 30 31 if ( lm1 < lm2 ) { 32 return (order == ORDER_DESC) ? -1 : 1; 33 } else if ( lm1 > lm2 ) { 34 return (order == ORDER_DESC) ? 1 : -1; 35 } else { 36 return 0; 37 } 38 } else if ( (o1 instanceof Comparable ) && (o2 instanceof Comparable ) ) { 39 return ((Comparable )o1).compareTo( ((Comparable )o2) ); 40 } 41 else 42 { 43 return -1; 44 } 45 } 46 public boolean equals(Object obj) { 47 if ( obj instanceof DateComparator ) { 48 return true; 49 } else { 50 return false; 51 } 52 } 53 } 54 | Popular Tags |