Java tutorial
/* * Copyright 2011-2016 ZXC.com All right reserved. This software is the confidential and proprietary information of * ZXC.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into with ZXC.com. */ package com.ms.commons.message.impl.filter; import java.io.Serializable; import org.apache.commons.lang.builder.HashCodeBuilder; /** * @author zxc Apr 13, 2014 10:44:38 PM */ public class MsgKey implements Serializable { /** * */ private static final long serialVersionUID = 1180128584171374842L; // ? private String to; // ????Email?--??80 private String content; // content private Integer originalLength; // private int hash; /** * Msgkey??? * * @param to to? * @param content content? */ public MsgKey(String to, String content, Integer originalLength) { this.to = to; this.content = content; this.originalLength = originalLength; } public String getTo() { return to; } /* * */ public int hashCode() { if (hash == 0) { HashCodeBuilder hashcodeBuilder = new HashCodeBuilder(17, 37); if (to != null) { hashcodeBuilder.append(to); } if (content != null) { hashcodeBuilder.append(content); } if (originalLength != null) { hashcodeBuilder.append(originalLength); } hash = hashcodeBuilder.toHashCode(); // if (content != null) { // // to? // hash = (to + content).hashCode(); // } else { // hash = to.hashCode(); // } // // orginalLengthHashcode // hash += originalLength; } return hash; } /* * ?? */ public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof MsgKey) { MsgKey anotherMsgKey = (MsgKey) anObject; if (anotherMsgKey.originalLength != originalLength) { return false; } if ((anotherMsgKey.to == null && to != null) || (anotherMsgKey.to != null && to == null) || (anotherMsgKey.content == null && content != null) || (anotherMsgKey.content != null && content == null)) { return false; } return anotherMsgKey.to.equals(to) && anotherMsgKey.content.equals(content); } return false; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("To=" + getTo()); sb.append(" content=" + content); sb.append(" orginalLength=" + originalLength); return sb.toString(); } }