美文网首页
计算机应用实践之---重写对象HashCode算法

计算机应用实践之---重写对象HashCode算法

作者: 左钦菠 | 来源:发表于2017-12-15 11:29 被阅读0次

@Getter

@Setter

public class ApplicationSplitRule  implements Serializable{

private Long id ;

private String splitRuleName;

private Integer supplyTypeId;

private String supplyTypeName;

private String vendorGroupIdList;//商家分组ID列表

private String vendorGroupNameList;//商家分组名称列表

private Integer invoiceAmountSource;//金额来源

private Integer status;//已保存,已生效

private Date created;//创建时间,

private Date modified;//更新时间,

private Integer yn;// 有效性

@Override

public int hashCode() {

int hash = 1;//选点质数 没啥到底

hash = hash * 13 + getId().hashCode();

hash = hash * 17 + getSupplyTypeId().hashCode();

hash = hash * 23 + getVendorGroupIdList().hashCode();

hash = hash * 31 + getInvoiceAmountSource().hashCode();

return hash;

}

@Override

public boolean equals(Object obj) {

if(this == obj){

return  true;

}

if(obj instanceof ApplicationSplitRule){

ApplicationSplitRule rule = (ApplicationSplitRule) obj;

if (this.getId().equals(rule.getId())

&&this.getSupplyTypeId().equals(rule.getSupplyTypeId())

&&this.getVendorGroupIdList().equals(rule.getVendorGroupIdList())

&& this.getInvoiceAmountSource().equals(rule.getInvoiceAmountSource())) {

return true;

} else {

return false;

}

}

return false;

}

}

相关文章

网友评论

      本文标题:计算机应用实践之---重写对象HashCode算法

      本文链接:https://www.haomeiwen.com/subject/stwrwxtx.html