自己定義list.containsメソッドは実用的です
2717 ワード
equals :
public class Tag implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8721123314415593476L;
// ID
private Integer tagId;
// ID
private Integer fatherId;
//
private String tagType;
// ID
private Integer keywordId;
//
private String tagName;
//
private Integer tagLevel;
//
private Date createTime;
//
private Date updateTime;
public Integer getKeywordId() {
return keywordId;
}
public void setKeywordId(Integer keywordId) {
this.keywordId = keywordId;
}
public Integer getTagId() {
return tagId;
}
public void setTagId(Integer tagId) {
this.tagId = tagId;
}
public Integer getFatherId() {
return fatherId;
}
public void setFatherId(Integer fatherId) {
this.fatherId = fatherId;
}
public String getTagType() {
return tagType;
}
public void setTagType(String tagType) {
this.tagType = tagType;
}
public String getTagName() {
return tagName;
}
public void setTagName(String tagName) {
this.tagName = tagName;
}
public Integer getTagLevel() {
return tagLevel;
}
public void setTagLevel(Integer tagLevel) {
this.tagLevel = tagLevel;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
@Override
public boolean equals(Object obj){
if(obj == null){
return false;
}else {
if(this.getClass() == obj.getClass()){
Tag tag = (Tag) obj;
if(this.getTagId().equals(tag.getTagId())){
return true;
}else{
return false;
}
}else{
return false;
}
}
}
:
public static void main(String[] args) {
List<Tag> list = new ArrayList<Tag>();
Tag a = new Tag();
a.setTagId(123);
list.add(a);
Tag b = new Tag();
b.setTagId(123);
System.out.println(list.contains(b)+"=======");
}
:true=======