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

📄 document.java

📁 一个p2p仿真软件
💻 JAVA
字号:
/*
 * @(#)Document.java	ver 1.2  6/20/2005
 *
 * Copyright 2005 Weishuai Yang (wyang@cs.binghamton.edu). 
 * All rights reserved.
 * 
 */

package gps.protocol;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.logging.Logger;


/**
 * Document base class, all specific protocol documents inherit from it. 
 *
 *
 * @author  Weishuai Yang
 * @version 1.2,  6/20/2005
 */
 
public class Document implements Serializable {
	
	/**
	 * singleton reference to debug log
	 */
	protected static Logger mDebugLog = Logger.getLogger("Debug");
	/**
	 * singleton reference to trace log
	 */
	protected static Logger mTraceLog = Logger.getLogger("Trace");
	
	/**
	 * next available id
	 */
	private static int mNextAvailableID = 0;


	/**
	 * Document List by ID, each id only has one documents
	 */
	public  static HashMap mDocumentListbyID = new LinkedHashMap();
	/**
	 * Document List by Key, each key may has more than one documents
	 */
	public static HashMap mDocumentListbyKey = new LinkedHashMap();		
	/**
	 * get next available id, and self increase
	 */
	public static int getNextAvailableID(){
		return mNextAvailableID++;
	}

	/**
	 * document id
	 */
	protected int mID = 0;
	/**
	 * document key
	 */
	protected String mKey = null;
	/**
	 * popularity ranking 0-9, 9 is the most popular
	 */
	protected int mPopularity = 0;
	
	/**
	 * document size, unit is byte;
	 */
	protected double mSize = 0;
	/**
	 * possible document status: EMPTY, WHOLE, PARTIAL
	 */
	public static final int EMPTY=0;
	/**
	 * possible document status: EMPTY, WHOLE, PARTIAL
	 */
	public static final int WHOLE=1;
	/**
	 * possible document status: EMPTY, WHOLE, PARTIAL
	 */
	public static final int PARTIAL=2;
	
	/**
	 * document status
	 */
	protected int mStatus=EMPTY;
	
	
	/**
	 * constructs a Document object with next available id
	 */
	 
	public Document(){
		this(getNextAvailableID());
	}
	/**
	 * constructs a Document object with a given id
	 */
	public Document(int id) {
		
		mID=id;
		if(mDocumentListbyID.get(new Integer(id))==null){
			mDocumentListbyID.put(new Integer(id),this);
		}
		else{
			mDebugLog.warning(toString()+": document already exist when trying to setID!");
		}
		if(mNextAvailableID<=id)
			mNextAvailableID=id+1;
	}	

	/**
	 * clear all the documents in the system
	 */
	public static void reset(){
		mNextAvailableID = 0;
		mDocumentListbyID.clear();	
		mDocumentListbyKey.clear();	
	}
	
	public void setKey(String newKey){
		if(mKey!=null){
			mDebugLog.warning(toString()+": Each document should only be setKey for once!");
		}

		mKey=newKey;
		
		if(mDocumentListbyKey.get(newKey)==null){
			ArrayList docs=new ArrayList(10);
			docs.add(this);
			mDocumentListbyKey.put(newKey,docs);
		}
		else{
			ArrayList docs=(ArrayList)mDocumentListbyKey.get(newKey);
			docs.add(this);
			mDocumentListbyKey.put(newKey,docs);
		}
	}
	
	public String getKey(){
		return mKey;
	}
	
	public int getID(){
		return mID;
	}
	
	
	public void setSize(double newSize){
		mSize=newSize;
	}
	
	public double getSize(){
		return mSize;
	}
	
	
	public void setWhole(){
		mStatus=WHOLE;
	}
	
	public void setStatus(int s){
		mStatus=s;
	}
	
	public int getStatus(){
		return mStatus;
	}
	
	public boolean isWhole(){
		return mStatus==WHOLE;
	}
	
	public boolean isEmpty(){
		return mStatus==EMPTY;
	}


	public int getPopularity(){
		return mPopularity;
	}
	
	public void setPopularity(int p){
		mPopularity=p;
	}
	
	public String toString(){
		return "Document("+mID+")-Key("+mKey+")";
	}
}

⌨️ 快捷键说明

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