package edu.mama.ls16.homework;
public class Buyer {
private String ID;
private String name;
public Buyer(String ID, String name) {<br /> this.ID = ID;<br /> this.name = name;<br /> }
public String getID() {<br /> return ID;<br /> }
public String getName() {<br /> return name;<br /> }
public void setName(String name) {<br /> this.name = name;<br /> }
//以sep为分隔符,将Buyer内容拼接成字符串<br /> public String toString(String sep) {<br /> StringBuilder sb=new StringBuilder();<br /> sb.append(this.ID).append(sep).append(this.name);<br /> return sb.toString();<br /> }
//使用Map,重写equals和hasCode方法<br /> @Override<br /> public boolean equals(Object obj) {<br /> if(this==obj)<br /> return true; //地址相等<br /> if(obj instanceof Buyer){<br /> Buyer other=(Buyer)obj;<br /> if(this.ID.equals(other.ID))<br /> return true; //ID相同<br /> }<br /> return false;<br /> }
@Override<br /> public int hashCode() {<br /> return this.ID.hashCode();<br /> }<br />}