zoukankan      html  css  js  c++  java
  • Java——重写hashCode()和euqals()方法

    package com.chantsoft.app.tc.org.beans;

    import com.chantsoft.core.base.AbstractBean;

    public class OrgRelationBean extends AbstractBean {

    /** 源类型:人员资源类型 */
    private Integer sourceCategory;

    /** 源ID:人员ID */
    private Long sourceId;

    /** 目标类型:部门,组等资源类型 */
    private Integer targetCategory;

    /** 目标ID:部门,组的ID */
    private Long targetId;

    /** 关系类型:参见OrgRelationCategoryEnum */
    private Integer relationCategory;

    /** 关系类型描述:未启用 */
    private Long relationValue1;

    /** 关系类型描述:未启用 */
    private String relationValue2;

    /** 单位 */
    private Long orgCorporationId;

    private Integer state;

    @Override
      // equals的重写
    public boolean equals(Object obj) {
    if (this == obj) {
    return true;
    }
    if (obj instanceof OrgRelationBean) {
    if (((OrgRelationBean) obj).sourceCategory.equals(this.sourceCategory)
    && ((OrgRelationBean) obj).sourceId.equals(this.sourceId)
    && ((OrgRelationBean) obj).targetCategory.equals(this.targetCategory)
    && ((OrgRelationBean) obj).targetId.equals(this.targetId)
    && ((OrgRelationBean) obj).relationCategory.equals(this.relationCategory)
    && ((OrgRelationBean) obj).relationValue1.equals(this.relationValue1)
    && ((OrgRelationBean) obj).relationValue2.equals(this.relationValue2)
    && ((OrgRelationBean) obj).orgCorporationId.equals(this.orgCorporationId)
    && ((OrgRelationBean) obj).state.equals(this.state)) {
    return true;
    }
    }

    return false;
    }

    @Override
      //hasCode的重写
    public int hashCode() {
    StringBuilder sb = new StringBuilder();
    sb.append(sourceCategory);
    sb.append(sourceId);
    sb.append(targetCategory);

    sb.append(targetId);
    sb.append(relationCategory);
    sb.append(relationValue1);

    sb.append(relationValue2);
    sb.append(orgCorporationId);
    sb.append(state);

    char[] charArr = sb.toString().toCharArray();
    int hash = 0;
    for(char c : charArr) {
    hash = hash * 131 + c;
    }
    return hash;
    }

    public OrgRelationBean() {

    }

    public OrgRelationBean(Integer sourceCategory,Long sourceId,Integer targetCategory,
    Long targetId,Integer relationCategory,Long orgCorporationId) {
    setNewId();
    this.sourceCategory = sourceCategory;
    this.sourceId = sourceId;
    this.targetCategory = targetCategory;
    this.targetId = targetId;
    this.relationCategory = relationCategory;
    this.orgCorporationId = orgCorporationId;
    this.state = 0;
    }

    public Integer getSourceCategory() {
    return this.sourceCategory;
    }

    public void setSourceCategory(Integer v) {
    this.sourceCategory = v;
    }

    public Long getSourceId() {
    return this.sourceId;
    }

    public void setSourceId(Long v) {
    this.sourceId = v;
    }

    public Integer getTargetCategory() {
    return this.targetCategory;
    }

    public void setTargetCategory(Integer v) {
    this.targetCategory = v;
    }

    public Long getTargetId() {
    return this.targetId;
    }

    public void setTargetId(Long v) {
    this.targetId = v;
    }

    public Integer getRelationCategory() {
    return this.relationCategory;
    }

    public void setRelationCategory(Integer v) {
    this.relationCategory = v;
    }

    public Long getRelationValue1() {
    return this.relationValue1;
    }

    public void setRelationValue1(Long v) {
    this.relationValue1 = v;
    }

    public String getRelationValue2() {
    return this.relationValue2;
    }

    public void setRelationValue2(String v) {
    this.relationValue2 = v;
    }

    public Long getOrgCorporationId() {
    return this.orgCorporationId;
    }

    public void setOrgCorporationId(Long v) {
    this.orgCorporationId = v;
    }

    public Integer getState() {
    return state;
    }

    public void setState(Integer state) {
    this.state = state;
    }

    }
  • 相关阅读:
    Lua基础之Function
    Lua基础之table详解
    Lua基础之语法
    详解C#中的反射(转载)
    Cocos-x 3.2:从C++过渡到Lua(转载)
    cocos2dx-Lua中出现的问题
    (转载)Cocos2dx-OpenGL ES2.0教程:纹理贴图(6)
    (转载)Cocos2dx-OpenGL ES2.0教程:你的第一个立方体(5)
    hdu 2098 分拆素数和(一个偶数拆分成两个不同素数和 拆法数量)
    51Nod
  • 原文地址:https://www.cnblogs.com/czq520/p/11647694.html
Copyright © 2011-2022 走看看