/**
* 自定义反向排序比较器*/
public class ReverseSort implements Comparator {
/**日期倒序*/
public int compare(Object obj1, Object obj2) {
if(obj1 instanceof BbsInformation && obj2 instanceof BbsInformation){
BbsInformation b1 =(BbsInformation)obj1;
BbsInformation b2 =(BbsInformation)obj2;
if(null!=b1.getBegintime()&& null!=b2.getBegintime()){
return -b1.getBegintime().compareTo(b2.getBegintime());
}else{
return 0;
}
}
return 0;
}
/**和当前日期比较
* entityDate实体类时间
* 超时返回false
* */
public static boolean compareTime(Date entityDate){
Date nowTime= new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(entityDate);
Date endDate =cal.getTime();
if(endDate.compareTo(nowTime)<0){//超时
return false;
}
return true;
}
}
使用
ReverseSort reverseSort = new ReverseSort();
reverseSort.compare(obj1, obj2);