📄 node.java
字号:
package de.uni_stuttgart.informatik.canu.mobisim.core;
import de.uni_stuttgart.informatik.canu.mobisim.notifications.*;
/**
* Title: Canu Mobility Simulation Environment
* Description:
* Copyright: Copyright (c) 2001-2003
* Company: University of Stuttgart
* @author Canu Research group
* @version 1.1
*/
/**
* Mobile node implementation.
* @author Illya Stepanov
* @author Gregor Schiele
*/
public class Node extends ExtendableObject implements Comparable
{
// ---------------------------------------------------------------------------
// attributes
// ---------------------------------------------------------------------------
//environment
/**
* Node's ID
*/
protected String id;
/**
* Node's Position
*/
protected Position3D position = new Position3D(0, 0, 0);
/**
* Constructor
*/
public Node()
{
}
// ---------------------------------------------------------------------------
// accessors
// ---------------------------------------------------------------------------
/**
* Gets the node's ID. <br>
* <br>
* @return node's ID
*/
public final String getID()
{
return id;
}
/**
* Returns a string representation of the object. <br>
* <br>
* @return string representation of the object
*/
public String toString()
{
return id;
}
/**
* Indicates whether this node is equals to some other node. <br>
* <br>
* @param o node to compare with
* @return true, if the nodes are the same
*
*/
public boolean equals(Object o)
{
if (o instanceof Node)
{
Node node = (Node)o;
if (id.equals(node.id))
return true;
}
return false;
}
/**
* Compares this object with another object for sort order. <br>
* <br>
* @param o another object
* @return a negative integer, zero, or a positive integer as this object
* is less, equal, or greater than the specified object
*/
public int compareTo(Object o)
{
return id.compareTo(((Node)o).id);
}
/**
* Gets the node's current position. <br>
* <br>
* @return node's current position
*/
public final Position3D getPosition()
{
return position;
}
/**
* Sets the node's current position. <br>
* <br>
* @param position new position
*/
public void setPosition(Position3D position)
{
this.position = position;
}
/**
* Initializes the object from XML tag. <br>
* <br>
* @param element source tag
* @throws Exception Exception if parameters are invalid
*/
public void load(org.w3c.dom.Element element) throws Exception
{
super.load(element);
// set id
String id_attr = element.getAttribute("id");
this.id=id_attr;
// process child tags
org.w3c.dom.NodeList list = element.getChildNodes();
int len=list.getLength();
for(int i=0; i<len; i++)
{
org.w3c.dom.Node item = list.item(i);
String tag = item.getNodeName();
if(tag.equals("#text"))
{
// skip it
continue;
}
else
if(tag.equals("#comment"))
{
// skip it
continue;
}
else
if(tag.equals("position"))
{
u.sendNotification(new LoaderNotification(this, u,
"Processing <position> tag"));
// read and set position
this.position = new Position3D((org.w3c.dom.Element)item);
u.sendNotification(new LoaderNotification(this, u,
"Finished processing <position> tag"));
}
}
// checkout
if (id.length()==0)
throw new Exception("Node "+toString()+" misses id definition");
}//proc
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -