zoukankan      html  css  js  c++  java
  • 如何判断同一类型的两个对象的属性值是否相等

    https://www.jianshu.com/p/cc9f95792fd3

    重写equals的时候重写hashcode


    @Override
    public int hashCode() {
    int result = employeeCode != null ? employeeCode.hashCode() : 0;
    result = 31 * result + (employeeName != null ? employeeName.hashCode() : 0);
    result = 31 * result + (ownerSite != null ? ownerSite.hashCode() : 0);
    result = 31 * result + (phone != null ? phone.hashCode() : 0);
    result = 31 * result + (address != null ? address.hashCode() : 0);
    result = 31 * result + (employeeType != null ? employeeType.hashCode() : 0);
    result = 31 * result + (blFlag != null ? blFlag.hashCode() : 0);
    result = 31 * result + (modifyUserCode != null ? modifyUserCode.hashCode() : 0);
    result = 31 * result + (orgCode != null ? orgCode.hashCode() : 0);
    result = 31 * result + (delFlag != null ? delFlag.hashCode() : 0);
    result = 31 * result + (title != null ? title.hashCode() : 0);
    result = 31 * result + (employeeSource != null ? employeeSource.hashCode() : 0);
    result = 31 * result + (telephone != null ? telephone.hashCode() : 0);
    result = 31 * result + (email != null ? email.hashCode() : 0);
    result = 31 * result + (userCardType != null ? userCardType.hashCode() : 0);
    result = 31 * result + (userCardId != null ? userCardId.hashCode() : 0);
    return result;
    }

    @Override
    public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    BaseEmployeeEntity that = (BaseEmployeeEntity) o;


    if (employeeCode != null ? !employeeCode.equals(that.employeeCode) : that.employeeCode != null) return false;
    if (employeeName != null ? !employeeName.equals(that.employeeName) : that.employeeName != null) return false;
    if (ownerSite != null ? !ownerSite.equals(that.ownerSite) : that.ownerSite != null) return false;
    if (phone != null ? !phone.equals(that.phone) : that.phone != null) return false;
    if (address != null ? !address.equals(that.address) : that.address != null) return false;
    if (employeeType != null ? !employeeType.equals(that.employeeType) : that.employeeType != null) return false;

    if (blFlag != null ? !blFlag.equals(that.blFlag) : that.blFlag != null) return false;


    if (modifyUserCode != null ? !modifyUserCode.equals(that.modifyUserCode) : that.modifyUserCode != null)
    return false;
    if (orgCode != null ? !orgCode.equals(that.orgCode) : that.orgCode != null) return false;
    if (delFlag != null ? !delFlag.equals(that.delFlag) : that.delFlag != null) return false;
    if (title != null ? !title.equals(that.title) : that.title != null) return false;

    if (employeeSource != null ? !employeeSource.equals(that.employeeSource) : that.employeeSource != null)
    return false;
    if (telephone != null ? !telephone.equals(that.telephone) : that.telephone != null) return false;


    if (userCardType != null ? !userCardType.equals(that.userCardType) : that.userCardType != null) return false;
    return userCardId != null ? userCardId.equals(that.userCardId) : that.userCardId == null;
    }
  • 相关阅读:
    将PHP文件生成静态文件源码
    Entity Framework Code First 学习日记(6)一对多关系
    Entity Framework Code First 学习日记(5)
    Entity Framework Code First 学习日记(3)
    Entity Framework Code First 学习日记(7)多对多关系
    Entity Framework Code First学习日记(2)
    Entity Framework Code First 学习日记(8)一对一关系
    Entity Framework Code First 学习日记(9)映射继承关系
    Entity Framework Code First 学习日记(10)兼容遗留数据库
    Entity Framework Code First 学习日记(4)
  • 原文地址:https://www.cnblogs.com/feifeicui/p/9158999.html
Copyright © 2011-2022 走看看