java Sort - sorting (ComparableComparator / ComparatorChain) in various attributes for an entity

After a, in the development process of the project, obtaining the express logistics information for the delivery routing information carried in reverse list sorted by time, so do some recording and summarizing 
// Get the Logistics Information ExpressRouteVO entity behind the
List <ExpressRouteVO> routeList = getExpressRouteByNo (entity.getBillNo ()) ;

. = ComparableComparator Comparator mycmp1
the getInstance () ;
// default is positive, we set reverse side

mycmp1 = ComparatorUtils. reversedComparator (mycmp1) ;
the ArrayList <Object> = SortFields new new the ArrayList <Object > () ;
sortFields.add ( new new BeanComparator ( "Time" , mycmp1)) ;
// create a sort chain

ComparatorChain MultiSort = new new ComparatorChain (the SortFields) ;
. the Collections the Sort (routeList , MultiSort);
Params.put ( "expressDataList" , routeList) ;

Second, the following are some references in the network to find the
Comparator mycmp1 = ComparableComparator.getInstance ();
. Mycmp1 = ComparatorUtils reversedComparator (mycmp1); // reverse order Comparator mycmp2 = ComparableComparator.getInstance ( ); . mycmp2 = ComparatorUtils nullHighComparator (mycmp2); // allow null attribute // declare object to be sorted, and indicate the collation is used, if not specified, then the default sort ArrayList <object> sortFields = new ArrayList < Object> (); sortFields.add (new new BeanComparator ( "Age", mycmp1)); // the primary sort (first ordering) sortFields.add (new new BeanComparator ( "Grade", mycmp2));// Sort times (second order) // create a sort chain ComparatorChain multiSort = new ComparatorChain (sortFields) ;
 


 




 


 
// start the real sort, according to the first main and rear sub-rule
Collections.sort (users, multiSort);

Third, by using the following ComparableComparator, we can easily compare the various attributes of the sort, here only briefly to be a record there was time to do more about the sort of entity method, the method of the underlying implementation for further understanding.

Reference:
https://blog.csdn.net/lizeyang/article/details/8877868
https://blog.csdn.net/qq_37107280/article/details/75570969


------------- ------------------
import java.io.Serializable;

/**
* 路由节点信息
*/
public class ExpressRouteVO implements Serializable {

private String time;

private String address;

private String remark;

private String opCode;

public String getTime() {
return time;
}

public void setTime(String time) {
this.time = time;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getRemark() {
return remark;
}

public void setRemark(String remark) {
this.remark = remark;
}

public String getOpCode() {
return opCode;
}

public void setOpCode(String opCode) {
this.opCode = opCode;
}
}

-------------------------------------------
 

Guess you like

Origin www.cnblogs.com/zluckiy/p/11455585.html