📄 entry.java
字号:
/*
* Entry.java
*
* Created on 2006年3月17日, 上午9:02
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package com.j2medev.sample.phonebook;
import java.io.*;
/**
*
* @author Admin
*/
public final class Entry {
private static int id_seq = 0;
private int id;
private String name;
private String mobile;
private String phone;
private String email;
private String address;
private String QQ;
/** Creates a new instance of Entry */
//实现自动加1,
private static int nextId(){
return id_seq++;
}
public Entry(){
}
public Entry(String name,String mobile,String phone,String email,String address,String QQ) {
this.id = nextId();
this.name = name;
this.mobile = mobile;
this.phone = phone;
this.email = email;
this.address = address;
this.QQ = QQ;
}
//得到成员变量的值;
public int getId(){
return id;
}
public String getEmail(){
return email;
}
public String getName(){
return name;
}
public String getMobile(){
return mobile;
}
public String getPhone(){
return phone;
}
public String getAddress(){
return address;
}
public String getQQ(){
return QQ;
}
//设置成员变量的值
public void setName(String name){
this.name = name;
}
public void setMobile(String mobile){
this.mobile = mobile;
}
public void setPhone(String phone){
this.phone = phone;
}
public void setEmail(String email){
this.email = email;
}
public void setAddress(String address){
this.address = address;
}
public void setQQ(String QQ){
this.QQ = QQ;
}
public boolean equals(Object obj){
if(this == obj)
return true;
if(obj instanceof Entry){
return ((Entry)obj).id == this.id;
}
return false;
}
public int hashCode(){
return id;
}
public byte[] serialize() throws IOException{
//System.out.println("执行到这儿了");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeUTF(name);
dos.writeInt(id);
dos.writeUTF(mobile);
dos.writeUTF(phone);
dos.writeUTF(email);
dos.writeUTF(address);
dos.writeUTF(QQ);
baos.close();
dos.close();
return baos.toByteArray();
}
public static Entry deserialize(byte[] data) throws IOException{
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
Entry entry = new Entry();
entry.name = dis.readUTF();
entry.id = dis.readInt();
entry.mobile = dis.readUTF();
entry.phone = dis.readUTF();
entry.email = dis.readUTF();
entry.address = dis.readUTF();
entry.QQ = dis.readUTF();
bais.close();
dis.close();
return entry;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -