比较自定义对象是否相等时,重写equals和hashcode方法

@Entity
@Table(name = "ne")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
public class Ne implements Serializable {
    @Id
//    @GenericGenerator(name = "Nuuid",strategy ="uuid" )
//    @GeneratedValue(strategy = GenerationType.AUTO,generator = "Nuuid")
    @Column(name = "neid")
    private String uuid;
    @Column(name = "nename")
    private String neName;
    @Column(name = "neip")
    private String neIp;
    private String sn;//snid?
    @Column(name = "portnum")
    private Integer portNum;//端口数量
    private String status; //设备状态,后续应该会用到 正常normal、故障fault;
    private String url;//防火墙配置的url只有防火墙有
    @Column(name = "netype")
    private String neType;//设备类型(switch,router,lb,fw.........)
    private String type;// 设备所属层级(spine,leaf)
    private Integer port; // 端口号
    @Column(length = 64, name = "vip")
    private String vtpIp;
    @Column(length = 64, name = "lip")
    private String loopbakIp;//还回口ip
    @Column(length = 64, name = "pnum")
    private String productNumber;
    @Column(length = 32, name = "version")
    private String systemVersion;//系统版本
    @Column(length = 64)
    private  String  customName;//页面显示的唯一标识
    private String mac ;//设备的系统mac,也可标识其唯一性

    public Ne() {
    }

    public Ne(String uuid, String neName, String neIp, String sn, Integer portNum, String status, String url, String
            neType, String type, Integer port, String vtpIp, String loopbakIp, String productNumber, String
            systemVersion, String customName, String mac) {
        this.uuid = uuid;
        this.neName = neName;
        this.neIp = neIp;
        this.sn = sn;
        this.portNum = portNum;
        this.status = status;
        this.url = url;
        this.neType = neType;
        this.type = type;
        this.port = port;
        this.vtpIp = vtpIp;
        this.loopbakIp = loopbakIp;
        this.productNumber = productNumber;
        this.systemVersion = systemVersion;
        this.customName = customName;
        this.mac = mac;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }


    public String getNeName() {
        return neName;
    }

    public void setNeName(String neName) {
        this.neName = neName;
    }

    public String getNeIp() {
        return neIp;
    }

    public void setNeIp(String neIp) {
        this.neIp = neIp;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public Integer getPortNum() {
        return portNum;
    }

    public void setPortNum(Integer portNum) {
        this.portNum = portNum;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }


    public String getNeType() {
        return neType;
    }

    public void setNeType(String neType) {
        this.neType = neType;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getVtpIp() {
        return vtpIp;
    }

    public void setVtpIp(String vtpIp) {
        this.vtpIp = vtpIp;
    }

    public String getLoopbakIp() {
        return loopbakIp;
    }

    public void setLoopbakIp(String loopbakIp) {
        this.loopbakIp = loopbakIp;
    }

    public String getProductNumber() {
        return productNumber;
    }

    public void setProductNumber(String productNumber) {
        this.productNumber = productNumber;
    }

    public String getSystemVersion() {
        return systemVersion;
    }

    public void setSystemVersion(String systemVersion) {
        this.systemVersion = systemVersion;
    }

    public String getCustomName() {
        return customName;
    }

    public void setCustomName(String customName) {
        this.customName = customName;
    }

    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;

        result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
        result = prime * result + ((neName == null) ? 0 : neName.hashCode());
        result = prime * result + ((neIp == null) ? 0 : neIp.hashCode());


        result = prime * result + ((sn == null) ? 0 : sn.hashCode());
        result = prime * result + ((portNum == null) ? 0 : portNum.hashCode());
        result = prime * result + ((status == null) ? 0 : status.hashCode());

        result = prime * result + ((url == null) ? 0 : url.hashCode());
        result = prime * result + ((neType == null) ? 0 : neType.hashCode());
        result = prime * result + ((type == null) ? 0 : type.hashCode());

        result = prime * result + ((port == null) ? 0 : port.hashCode());
        result = prime * result + ((vtpIp == null) ? 0 : vtpIp.hashCode());
        result = prime * result + ((loopbakIp == null) ? 0 : loopbakIp.hashCode());
        result = prime * result + ((productNumber == null) ? 0 : productNumber.hashCode());
        result = prime * result + ((systemVersion == null) ? 0 : systemVersion.hashCode());
        result = prime * result + ((customName == null) ? 0 : customName.hashCode());
        result = prime * result + ((mac == null) ? 0 : mac.hashCode());
        return result;

    }

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

        Ne ne = (Ne) obj;
        if (uuid == null) {
            if (ne.getUuid() != null) {
                return false;
            }
        } else if (!uuid.equals(ne.uuid)) {
            return false;
        }
        if (neName == null) {
            if (ne.getNeName() != null) {
                return false;
            }
        } else if (!neName.equals(ne.getNeName())) {
            return false;
        }

        if (neIp == null) {
            if (ne.getNeIp() != null) {
                return false;
            }
        }else if (!neIp.equals(ne.getNeIp())) {
            return false;
        }

        if (sn == null) {
            if (ne.getSn() != null) {
                return false;
            }
        }else if (!sn.equals(ne.getSn())) {
            return false;
        }

        if (portNum == null) {
            if (ne.getPortNum() != null) {
                return false;
            }
        }else if (!portNum.equals(ne.getPortNum())) {
            return false;
        }

        if (status == null) {
            if (ne.getStatus() != null) {
                return false;
            }
        } else if (!status.equals(ne.getStatus())) {
            return false;
        }

        if (url == null) {
            if (ne.getUrl() != null) {
                return false;
            }
        }else if (!url.equals(ne.getUrl())) {
            return false;
        }

        if (neType == null) {
            if (ne.getNeType() != null) {
                return false;
            }
        }else if (!neType.equals(ne.getNeType())) {
            return false;
        }

        if (type == null) {
            if (ne.getType() != null) {
                return false;
            }
        }else if (!type.equals(ne.getType())) {
            return false;
        }


        if (port == null) {
            if (ne.getPort() != null) {
                return false;
            }
        } else if (!port.equals(ne.getPort())) {
            return false;
        }

        if (vtpIp == null) {
            if (ne.getVtpIp() != null) {
                return false;
            }
        } else if (!vtpIp.equals(ne.getVtpIp())) {
            return false;
        }

        if (loopbakIp == null) {
            if (ne.getLoopbakIp() != null) {
                return false;
            }
        }else if (!loopbakIp.equals(ne.getLoopbakIp())) {
            return false;
        }

        if (productNumber == null) {
            if (ne.getProductNumber() != null) {
                return false;
            }
        }else if (!productNumber.equals(ne.getProductNumber())) {
            return false;
        }

        if (systemVersion == null) {
            if (ne.getSystemVersion() != null) {
                return false;
            }
        }else if (!systemVersion.equals(ne.getSystemVersion())) {
            return false;
        }
        if (customName == null) {
            if (ne.getCustomName() != null) {
                return false;
            }
        }else if (!customName.equals(ne.getCustomName())) {
            return false;
        }
        if (mac == null) {
            if (ne.getMac() != null) {
                return false;
            }
        }else if (!mac.equals(ne.getMac())) {
            return false;
        }

        return true;
}

}

 

你可能感兴趣的:(problem)