Collections使用
private void listSortByDate(List<CTagSet> listSort,int sortType, String sortRow)
{
Collections.sort(list,new CTagSetComparator(sortType,sortRow));
}
static class CTagSetComparator implement Comparator<CTagSet>, Serializable
{
int sortType;
String sortRow;
int flag = -1;
public CTagSetComparator(int sortType, String sortRow){
this.sortType = sortType;
this.sortRow = sortRow;
}
public int compare(CTagSet s1, CTagSet s2)
{
if(null == sortRow || sortRow.isEmpty())
{
sortRow = "RECDATE"
}
String recDateStr1 = s1.GetValue(sortRow);
String recDateStr2 = s2.GetValue(sortRow);
if(null != recDateStr1 && null != recDateStr2)
{
try
{
Date recDateStr1 = Dates.parseDateTime(recDateStr1);
Date recDateStr2 = Dates.parseDateTime(recDateStr2);
flag = recDateStr1.compareTo(recDate2);
}catch(Exception e)
{
return flag;
}
}else{
return flag;
}
return flag*sortType;
}
}