HashCodeBuilder&&EqualsBuilder

 

//EqualsBuilder
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(firstName).append(lastName).toHashCode();
	}

	public boolean equals(Object o) {
		boolean equals = false;
		if (o != null && Equals_hashCode.class.isAssignableFrom((Class<?>) o)) {
			Equals_hashCode pc = (Equals_hashCode) o;
			equals = (new EqualsBuilder().append(firstName, pc.firstName).append(lastName, pc.lastName)).isEquals();
		}
		return equals;
	}

 

public boolean equals(Object other) {
	         if ( (this == other ) ) return true;
			 if ( (other == null ) ) return false;
			 if ( !(other instanceof MenuLink) ) return false;
			 MenuLink castOther = ( MenuLink ) other; 
			 
			 return  ( (this.getId()==castOther.getId()) || ( this.getId()!=null && castOther.getId()!=null && this.getId().equals(castOther.getId()) ) );
	   }
	   
	   public int hashCode() {
	        HashCodeBuilder hcb = new HashCodeBuilder(17, 37);
	        hcb.append(getId());

	        return hcb.toHashCode();
	    }

 

你可能感兴趣的:(EqualsBuilder,HashCodeBuilder)