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

📄 node.java

📁 一个p2p仿真软件
💻 JAVA
字号:
/** * @(#)Node.java	ver 1.2  6/20/2005 * * Modified by Weishuai Yang (wyang@cs.binghamton.edu).  *  * this file is based on KOM / LetsQoS Topology Conversion Tools */package gps.network.graph;import java.util.ArrayList;import java.util.HashMap;import java.util.logging.Logger;import gps.event.SimEvent;import gps.event.SimEventHandler;import gps.network.Topology;import gps.protocol.Agent;/** * Represents a network node.  * To get and change the properties of the node call node.getProperties(). * @author Oliver Heckmann */public class Node implements SimEventHandler {	/**	 * singleton reference to topology	 */	protected static Topology mTopology=Topology.getInstance();	/**	 * singleton reference to debug log	 */	protected static Logger mDebugLog = Logger.getLogger("Debug");		/**	 * provide next available id for automatically indexing	 */	public static int mNextAvailableID = 0;		/**	 * mNodeID decides the position in Node[] list	 */	protected int mNodeID = 0;		/**	 * activate status	 */	protected boolean mActivated = true;	/**	 * agents attached on this node	 */	protected ArrayList mAgentList=new ArrayList(1);	/**	 * links connected with this node	 */	protected HashMap mLinks=new HashMap(1);	/**	 * node properties	 */	protected NodeProperties preProperties = new NodeProperties();	/**	 * reset values	 */	public void reset(){		mActivated = true;		mAgentList.clear();	}	// *********** Constructors	/** Creates new Node, standard constructor.	 */	public Node(){		this(mNextAvailableID++);	}			/**	 * initialization with specified node id	 * 	 * @param i node id	 */		 	public Node(int i){		setID(i);	}	/**	 * set id	 * @param i new id	 */	public void setID(int i){		mNodeID=i;		if(i+1>mNextAvailableID)			mNextAvailableID=i+1;	}	/**	 * gets node id	 * 	 * @return node id	 */	public int getID(){		return mNodeID;	}		/**	 * gets node id	 * @return node id	 */	public int getKey() {		return getID();		//return key;	}	/**	 * set id	 * @param key new id	 */	protected void setKey(int key) {		setID(key);		//this.key = key;	}	// ************ Properties	/**	 * gets node properties	 * @return node properties	 */	public NodeProperties getProperties() {		return preProperties;	}	/**	 * sets node propertes	 * @param p node properties	 */	public void setProperties(NodeProperties p) {		this.preProperties = p;	}	/**	 * gets agent list attached on this node	 */	public ArrayList getAgentList(){		return mAgentList;	}	/**	 * add a link between this node and another node	 * @param n another node	 * @param l link between two nodes	 */	public void hasLinkTo(Node n, Link l){		mLinks.put(n,l);	}	/**	 * gets link to another node	 * @param n destination node	 * @return link	 */	public Link getLinkTo(Node n){		return (Link)mLinks.get(n);	}		/**	 * checks activity	 * 	 * @return true if activated	 */	public boolean isActive(){		return mActivated;	}		/**	 * handles node level event	 *	 * @param e is the event to be handled	 * @return true if already handled	 * 	 */	public boolean handle(SimEvent e){		if(e.getType()==SimEvent.SIM_NODE_ACTIVE) {			//make this node active			mActivated=true;			return true;		}		else if(e.getType()==SimEvent.SIM_NODE_DEACTIVE) {			//make this node inactive			mActivated=false;			return true;		}		return false;	};	/**	 * attachs agents on that node	 *	 * @param a the agent to be attached	 * 	 */	public void attach(Agent a){		mAgentList.add(a);	}	/**	 * gets string description	 *	 * @return string description	 *	 */	public String toString() {		String ret = "Node("+mNodeID+")";		if (getProperties() != null) {			ret += ": x="				+ getProperties().getX()				+ ", y="				+ getProperties().getY()				+ ", type="				+ getProperties().getType();		}		return ret;	}}

⌨️ 快捷键说明

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