利用Collections.sort自定義排序

List<CustomerCouponRpcVo> couponList = new ArrayList<CustomerCouponRpcVo>();

//根據金額排序
Collections.sort(couponList,new Comparator<CustomerCouponRpcVo>(){
@Override
public int compare(CustomerCouponRpcVo o1, CustomerCouponRpcVo o2) {
double am1 = o1.getAmount();
double am2 = o2.getAmount();	
return am1<am2?1:-1;
}	
});
package com.pz998.rpc.model.vo;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class CustomerCouponRpcVo {
private Integer index;
private Long id;
private String name;
private String customerName;
private String customerPhone;
private Long customerId;
private Date getTime;
private String useTime;
private String couponName;
private String couponCode;
private String ruleInfo;
private Integer type;
private Double amount;
private Double actualAmount;
private Date effectTime;
private Date invalidTime;
private Integer state;
private String stateName;
private Integer supportFullCut;
private Double fullCutAmount;
private boolean isAvailable;
private String invalidReason;
private String confirmHospital;
private Integer useCity;
private Integer source;
private Long couponId;

public static final Integer COUPON_STATE_WSX = 1011;//未生效
public static final Integer COUPON_STATE_WSY = 1012;//未使用
public static final Integer COUPON_STATE_YGQ = 1013;//已過期
public static final Integer COUPON_STATE_YSY = 1014;//已使用

public static final Integer SUPPORT_FULLCUT_YES = 1;//支持滿減
public static final Integer SUPPORT_FULLCUT_NO = 0;//不支持滿減


public static final Integer USE_CITY_BX = 201;//不限制
public static final Integer USE_CITY_WH = 202;//武漢
public static final Integer USE_CITY_BJ = 203;//北京

public static Map<Integer,String> stateMap = new HashMap<Integer,String>();

static{
stateMap.put(COUPON_STATE_WSX,"未生效");
stateMap.put(COUPON_STATE_WSY, "未使用");
stateMap.put(COUPON_STATE_YGQ, "已過期");
stateMap.put(COUPON_STATE_YSY, "已使用");
}

public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public Date getGetTime() {
return getTime;
}
public void setGetTime(Date getTime) {
this.getTime = getTime;
}
public String getCouponName() {
return couponName;
}
public void setCouponName(String couponName) {
this.couponName = couponName;
}
public String getRuleInfo() {
return ruleInfo;
}
public void setRuleInfo(String ruleInfo) {
this.ruleInfo = ruleInfo;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}



public Date getEffectTime() {
return effectTime;
}
public void setEffectTime(Date effectTime) {
this.effectTime = effectTime;
}
public Date getInvalidTime() {
return invalidTime;
}
public void setInvalidTime(Date invalidTime) {
this.invalidTime = invalidTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}

public Double getFullCutAmount() {
return fullCutAmount;
}
public void setFullCutAmount(Double fullCutAmount) {
this.fullCutAmount = fullCutAmount;
}
public boolean isAvailable() {
return isAvailable;
}
public void setAvailable(boolean isAvailable) {
this.isAvailable = isAvailable;
}
public String getInvalidReason() {
return invalidReason;
}
public void setInvalidReason(String invalidReason) {
this.invalidReason = invalidReason;
}
public Integer getSupportFullCut() {
return supportFullCut;
}
public void setSupportFullCut(Integer supportFullCut) {
this.supportFullCut = supportFullCut;
}
public Integer getUseCity() {
return useCity;
}
public void setUseCity(Integer useCity) {
this.useCity = useCity;
}
public String getUseTime() {
return useTime;
}
public void setUseTime(String useTime) {
this.useTime = useTime;
}
public String getConfirmHospital() {
return confirmHospital;
}
public void setConfirmHospital(String confirmHospital) {
this.confirmHospital = confirmHospital;
}
public Double getActualAmount() {
return actualAmount;
}
public void setActualAmount(Double actualAmount) {
this.actualAmount = actualAmount;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerPhone() {
return customerPhone;
}
public void setCustomerPhone(String customerPhone) {
this.customerPhone = customerPhone;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
public String getStateName() {
return stateName;
}
public void setStateName(String stateName) {
this.stateName = stateName;
}
public String getCouponCode() {
return couponCode;
}
public void setCouponCode(String couponCode) {
this.couponCode = couponCode;
}
public Integer getSource() {
return source;
}
public void setSource(Integer source) {
this.source = source;
}
public Long getCouponId() {
return couponId;
}
public void setCouponId(Long couponId) {
this.couponId = couponId;
}


}

----
spring mvc+tomcat源碼分析視頻(鏈接複製在瀏覽器打開)

https://study.163.com/course/courseMain.htm?share=2&shareId=480000001919582&courseId=1209399899&_trace_c_p_k2_=6d81bc445e9c462ab8d6345e40f6b0bf

發佈了89 篇原創文章 · 獲贊 5 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章