⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientdata.java

📁 JAVA实现的聊天工具,可以容纳最多10个用户 1.本系统需要JDK1.5 或更高版本的支持。 2.serverDatabase为服务器端的数据文件. 若使用现有数据,可用帐号:1, 密码
💻 JAVA
字号:
//class to record client data
import java.io.Serializable;
import java.util.*;
public class ClientData implements Comparable<ClientData>,Serializable{
	private long id;  //id is the default ordering
	private String ip; //client's ip
	private transient boolean online=false;
	private String name;
	private String password;
	
	private String mail;
	private String age;
	private String sex;
	private String from;
	private Date registryDate;
	
	private List<Long> friends = new LinkedList<Long>(); //store this client's friends' id
	
	//constructor 
	public ClientData(String ip,String name,String password,String mail,String age,String sex,String from){
		this.ip=ip;
		//System.out.println("client's ip:"+ip.toString());
		id=  Server.getServerDatabase().getNewClientID()+1;
		
		this.name=name;
		this.password=password;
		this.mail=mail;
		this.age=age;
		this.sex=sex;
		this.from=from;		
		online=false;
		registryDate=new Date();
	}
	
	public ClientData(long id){  //constructor used when Collections.binarySerach() needed
		this.id=id;
	}
	
	public int compareTo(ClientData cd){				
		boolean b=(id==cd.getID());
		return (b==true ? 0 : id>cd.getID() ? 1 : -1);
	}
	
	void setName(String name){
		this.name=name;
	}
	
	void setPassword(String password){
		this.password=password;
	}
	
	List<Long> getFriends(){
		return friends;
	}
	
	void updateIP(String ip){
		this.ip=ip;
	}
	
	String getName(){
		return name;
	}
	
	String getPassword(){
		return password;
	}
	
	long getID(){
		return id;
	}
	
	String getIP(){
		return ip;
	}
	
	String getAge(){
		return age;
	}
	
	String getMail(){
		return mail;
	}
	
	String getSex(){
		return sex;		
	}
	
	String getFrom(){
		return from;
	}
	
	void markOnline(){
		online=true;
	}
	
	void markOffline(){
		online=false;
	}
	
	boolean isOnline(){
		return online==true;
	}
	
	void addFriends(List<Long> f){
		friends.addAll(f);
		Collections.sort(friends);
	}
	
	Date getRegistryDate(){
		return registryDate;
	}
	
	List<Long> delFriends(List<Long> df){ //df: list of friends to del
		List<Long> tempList=new LinkedList<Long>(); //contain friends not be deled
		Long tempLong;
		int signal;
		for(int i=0;i<df.size();i++){
			tempLong=df.get(i);
			signal=Collections.binarySearch(friends,tempLong);
			
			if(signal<0){ //not a friend in list
				tempList.add(tempLong);
				continue;
			}
			
			friends.remove(signal);
		}
		
		if(tempList.size()==0) //all have been deled
			return null; 
		else
			return tempList; //some are not found
	}
	
	void viewAllFriends(){
		ListIterator li=friends.listIterator();
		System.out.println("**********");
		for(;li.hasNext();)
			System.out.println("Friend's ID:"+li.next());
	}
	
	void removeAllFriends(){
		friends.removeAll(friends);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -