• 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;
    }

    }
  • 相关阅读:
    图像裁剪功能,鼠标抬起移除事件,不只是想去掉鼠标抬起时的裁剪事件,重要的是jquery绑定的都是dom2级事件
    在 JavaScript 里 + 会把一些字符转化成数字
    ++[[]][+[]]+[+[]] == 10 //true
    node 接口
    windows下,node.js默认执行的根目录
    鸟速度不匀速的方法Math.sqrt(this.i++); 开根号
    rotate 里面的是弧度不是度,如果需要度则要转成度 Math.PI/180
    定义一个数,它可能为正 也可能为负 var num = Math.pow(-1,parseInt(Math.random() * 2) + 1);
    如何单独使用modelsim进行仿真
    Xilinx开发板信息
  • 原文地址:https://www.cnblogs.com/czq520/p/11647694.html
Copyright © 2020-2023  润新知