package execise;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int l = 0;
List l1 = new ArrayList();
PhoneNumber pn = new PhoneNumber("021", "852369", "789");
l1.add(pn);
l1.add(new PhoneNumber("021", "456123", "123"));
l1.add(new PhoneNumber("021", "456473", "145"));
l1.add(new PhoneNumber("021", "456153", "323"));
l1.add(new PhoneNumber("021", "456120", "923"));
for (Iterator it = l1.iterator(); it.hasNext(); ){
System.out.println(l1.get(l));
it.next();
l++;
}
l1.add(5,pn);
System.out.println(l1.contains(pn));
System.out.println(l1.lastIndexOf(pn));
Map<String, PhoneNumber> m = new HashMap<String, PhoneNumber>();
m.put("a", new PhoneNumber("021", "555555", "555"));
m.put("b", new PhoneNumber("021", "111111", "111"));
m.put("c", new PhoneNumber("021", "999999", "999"));
Set s = m.keySet();
Collection c = m.values();
Set s1 = m.entrySet();
Set s2 = new HashSet();
s2.add(new PhoneNumber("021", "555555", "555"));
s2.add(new PhoneNumber("021", "111111", "111"));
s2.add(new PhoneNumber("021", "999999", "999"));
for (Iterator it = s2.iterator(); it.hasNext();){
System.out.println(it.next());
}
System.out.println(s);
System.out.println(c);
for (Iterator it = s1.iterator(); it.hasNext();){
Map.Entry me = (Map.Entry)it.next();
System.out.println(me.getKey() + "--" + me.getValue());
}
for (Iterator it = s1.iterator(); it.hasNext();){
Map.Entry me = (Map.Entry)it.next();
me.setValue("aa" + it);
System.out.println(me.getKey() + "---" + me.getValue());
//System.out.println(me.getKey() + "--" + me.getValue());
}
for (Object sp : l1) {
System.out.println(sp);
}
}
}
class PhoneNumber implements Cloneable{
private String quhao;
private String dianhuahaoma;
private String kuozhan;
public String getQuhao() {
return quhao;
}
public void setQuhao(String quhao) {
this.quhao = quhao;
}
public String getDianhuahaoma() {
return dianhuahaoma;
}
public void setDianhuahaoma(String dianhuahaoma) {
this.dianhuahaoma = dianhuahaoma;
}
public String getKuozhan() {
return kuozhan;
}
public void setKuozhan(String kuozhan) {
this.kuozhan = kuozhan;
}
public PhoneNumber(String dianhuahaoma, String kuozhan, String quhao){
this.dianhuahaoma = dianhuahaoma;
this.kuozhan = kuozhan;
this.quhao = quhao;
}
public PhoneNumber(){
}
public boolean equals (Object obj) {
if (null == obj) {
return false;
}
if (this == obj) {
return true;
}
if (!(obj instanceof PhoneNumber)) {
return false;
}
PhoneNumber temp = (PhoneNumber) obj;
if ((this.dianhuahaoma.equals(temp.dianhuahaoma)) && (this.kuozhan.equals(temp.kuozhan)) && (this.quhao.equals(temp.quhao))) {
return true;
}
else{
return false;
}
}
protected Object clone() throws CloneNotSupportedException{
super.clone();
PhoneNumber result = new PhoneNumber();
result.setDianhuahaoma(this.dianhuahaoma);
result.setKuozhan(this.kuozhan);
result.setQuhao(this.quhao);
return result;
}
public String toString(){
return this.getClass().getName() + '@' + Integer.toHexString(hashCode());
}
public int hashcode(){
int result = 17;
result = result * 37 + quhao.length();
result = result * 37 + dianhuahaoma.length();
result = result * 37 + kuozhan.length();
return result;
}
protected void finalize(){
}
public void setContent(String dianhuahaoma, String kuozhan, String quhao) {
this.dianhuahaoma = dianhuahaoma;
this.kuozhan = kuozhan;
this.quhao = quhao;
}
}