public class Node extends Properties implements ClockListener, java.lang.Comparable<Node>
Modifier and Type | Field and Description |
---|---|
static Color |
DEFAULT_COLOR |
static double |
DEFAULT_DIRECTION |
static int |
DEFAULT_ICON_SIZE |
properties
Constructor and Description |
---|
Node() |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Node o) |
void |
die()
Request the
Node to die by the end of the round. |
void |
disableWireless()
Disables this node's wireless capabilities.
|
double |
distance(double x,
double y)
Returns the distance between this node and the specified 2D location.
|
double |
distance(double x,
double y,
double z)
Returns the distance between this node and the specified 3D location.
|
double |
distance(Node n)
Returns the distance between this node and the specified node.
|
double |
distance(Point p)
Returns the distance between this node and the specified 3D location.
|
void |
enableWireless()
Enables this node's wireless capabilities.
|
Color |
getColor()
Returns the color of this node.
|
Link |
getCommonLinkWith(Node n)
Returns the undirected link whose endpoints are this node and the
specified node, if any such link exists.
|
double |
getCommunicationRange()
Returns the communication range of this node (as a radius).
|
double |
getDirection()
Returns the current direction angle of this node (in radians).
|
java.lang.String |
getIcon()
Returns the icon of the this node.
|
int |
getIconSize()
Returns the
Node 's icon's desired size. |
int |
getID()
Returns the identifier of this node.
|
Link |
getInLinkFrom(Node n)
Returns the directed link whose destination is this node and sender is
the specified node, if any such link exists.
|
java.util.List<Link> |
getInLinks()
Returns a list containing all links for which this node is the
destination.
|
java.util.List<Node> |
getInNeighbors()
Returns a list containing every node serving as source for an adjacent
directed link.
|
java.lang.Object |
getLabel()
Returns the label of this node.
|
java.util.List<Link> |
getLinks()
Returns a list containing all undirected links adjacent to this node.
|
java.util.List<Link> |
getLinks(boolean directed)
Returns a list containing all adjacent links of the specified type.
|
Point |
getLocation()
Returns the location of this node.
|
java.util.List<Message> |
getMailbox()
Returns a list of messages representing the mailbox of this node.
|
java.util.List<Node> |
getNeighbors()
Returns a list containing every node located at the opposite endpoint
of an adjacent undirected links.
|
java.util.List<Message> |
getOutbox()
Returns a list of the messages that this node is about to send.
|
java.util.List<Link> |
getOutLinks()
Returns a list containing all links for which this node is the
sender.
|
Link |
getOutLinkTo(Node n)
Returns the directed link whose sender is this node and destination is
the specified node, if any such link exists.
|
java.util.List<Node> |
getOutNeighbors()
Returns a list containing every node serving as destination for an
adjacent directed link.
|
java.util.List<Node> |
getSensedNodes()
Returns a list containing every node located within the sensing range
The returned list can be modified without side effect.
|
double |
getSensingRange()
Returns the sensing range of this node (as a radius).
|
int |
getTime()
Returns the current time (current round number).
|
Topology |
getTopology()
Returns the parent
Topology of this node, if any. |
double |
getX()
Returns the x-coordinate of this node.
|
double |
getY()
Returns the y-coordinate of this node.
|
double |
getZ()
Returns the z-coordinate of this node.
|
boolean |
hasNeighbors()
Indicates whether this node has at least one neighbor (undirected)
|
boolean |
isDying()
Returns the dying status of the
Node . |
boolean |
isWirelessEnabled()
Indicates whether this node has wireless capabilities enabled.
|
void |
move()
Translates the location of this node by one unit towards
the node's current direction.
|
void |
move(double distance)
Translates the location of this node by the specified distance towards
the node's current direction.
|
protected void |
notifyNodeMoved() |
void |
onClock()
Override this method to perform some action upon clock pulse.
|
void |
onDirectedLinkAdded(Link link)
Called when an adjacent directed link is added.
|
void |
onDirectedLinkRemoved(Link link)
Called when an adjacent directed link is removed.
|
void |
onLinkAdded(Link link)
Called when an adjacent undirected link is added.
|
void |
onLinkRemoved(Link link)
Called when an adjacent undirected link is removed.
|
void |
onMessage(Message message)
Called when this node receives a
Message . |
void |
onMovement()
Override this method to perform some action when the node moves.
|
void |
onPostClock()
Override this method to perform some action just after clock pulse.
|
void |
onPreClock()
Override this method to perform some action just before clock pulse.
|
void |
onSelection()
Called when this node is selected (e.g. middle click in the UI)
|
void |
onSensingIn(Node node)
Called when another node is sensed for the first time.
|
void |
onSensingOut(Node node)
Called when a sensed node is no more sensed.
|
void |
onStart()
Override this method to re-initialise your node (e.g. your variables).
|
void |
onStop()
This method is called just before
the node is removed from the topology.
|
void |
send(Node destination,
Message message)
Sends a message from this node to the specified destination node.
|
void |
send(Node destination,
java.lang.Object content)
Deprecated.
Please use
send(Node, Message) instead. |
void |
sendAll(Message message)
Sends a message to all neighbors.
|
void |
sendAll(java.lang.Object content)
Deprecated.
Please use
sendAll(Message) instead. |
void |
sendRetry(Node destination,
Message message)
Same method as send(), but retries to send the message later
if the link to the destination disappeared during transmission.
|
void |
sendRetry(Node destination,
java.lang.Object content)
Deprecated.
Please use
sendRetry(Node, Message) instead. |
void |
setColor(Color color)
Sets the color of this node.
|
void |
setCommunicationRange(double range)
Activates the wireless capabilities of this node and sets
its communication range to the specified radius.
|
void |
setDirection(double angle)
Sets the direction angle of this node (in radians).
|
void |
setDirection(Point p)
Sets the direction angle of this node using the specified reference
point.
|
void |
setDirection(Point p,
boolean opposite)
Sets the direction angle of this node using the specified reference
point.
|
void |
setIcon(java.lang.String fileName)
Sets the icon of this node.
|
void |
setIconSize(int iconSize)
Sets the
Node 's icon's desired size. |
void |
setID(int ID)
Sets the identifier of this node.
|
void |
setLabel(java.lang.Object label)
Sets the label of this node.
|
void |
setLocation(double x,
double y)
Changes this node's location to the specified coordinates.
|
void |
setLocation(double x,
double y,
double z)
Changes this node's location to the specified coordinates.
|
void |
setLocation(Point loc)
Changes this node's location to the specified 2D point.
|
void |
setSensingRange(double range)
Sets the sensing range of this node to the specified radius.
|
void |
setWirelessStatus(boolean enabled)
Set wireless capabilities status
|
java.lang.String |
toString()
Returns a string representation of this node.
|
void |
translate(double dx,
double dy)
Translates the location of this node by the specified coordinates.
|
void |
translate(double dx,
double dy,
double dz)
Translates the location of this node by the specified coordinates.
|
void |
wrapLocation()
Changes this node's location modulo the iconSize of topology.
|
addPropertyListener, getProperty, hasProperty, removeProperty, removePropertyListener, setProperty
public static final Color DEFAULT_COLOR
public static final int DEFAULT_ICON_SIZE
public static final double DEFAULT_DIRECTION
public int getID()
public void setID(int ID)
Node
s have an identifier by default,
which is the smallest available integer.ID
- the new identifier.public Topology getTopology()
Topology
of this node, if any.Topology
, or null if the node is orphan.public void onSelection()
public void onStart()
public void onStop()
public void onPreClock()
public void onClock()
onClock
in interface ClockListener
public void onPostClock()
public void onMovement()
public void onMessage(Message message)
Message
.message
- the received Message
.public void onLinkAdded(Link link)
link
- the added Link
.public void onLinkRemoved(Link link)
link
- the removed Link
.public void onDirectedLinkAdded(Link link)
link
- the added Link
.public void onDirectedLinkRemoved(Link link)
link
- the removed Link
.public void onSensingIn(Node node)
node
- the Node
that has been sensed.public void onSensingOut(Node node)
node
- the Node
that is not sensed anymore.public void die()
Node
to die by the end of the round.public boolean isDying()
Node
.true
if the Node
is dying or already dead; returns false
otherwise.public double getX()
public double getY()
public double getZ()
public void setColor(Color color)
public void setIcon(java.lang.String fileName)
node.setIcon("/filesystem/path/to/image");
node.setIcon("/package/path/to/image");
fileName
- a String
leading to the icon.public java.lang.String getIcon()
String
leading to the icon.public int getIconSize()
Node
's icon's desired size.Node
's icon, as an integer.public void setIconSize(int iconSize)
Node
's icon's desired size.iconSize
- the new desired size of this Node
's icon, as an integer.public java.lang.Object getLabel()
Object
.public void setLabel(java.lang.Object label)
label
- the Object
representing the new label of the node.public double getCommunicationRange()
public void setCommunicationRange(double range)
range
- the new communication range, as a double.public boolean isWirelessEnabled()
public void enableWireless()
public void disableWireless()
public void setWirelessStatus(boolean enabled)
enabled
- the new wireless status: true to enable,
false otherwise.public double getSensingRange()
public void setSensingRange(double range)
range
- the new sensing range, as a double.public Point getLocation()
Point
.public void setLocation(double x, double y)
x
- The abscissa of the new location.y
- The ordinate of the new location.public void setLocation(double x, double y, double z)
x
- The abscissa of the new location.y
- The ordinate of the new location.z
- The ordinate of the new location.public void setLocation(Point loc)
loc
- The new location point.public void wrapLocation()
public void translate(double dx, double dy)
dx
- The abscissa component.dy
- The ordinate component.public void translate(double dx, double dy, double dz)
dx
- The abscissa component.dy
- The ordinate component.dz
- The applicate component.public int getTime()
public double getDirection()
public void setDirection(double angle)
angle
- The angle in radians.public void setDirection(Point p)
p
- The reference Point
.public void setDirection(Point p, boolean opposite)
p
- The reference Point
.opposite
- true if the new direction should be the opposite of the reference point.public void move()
public void move(double distance)
distance
- the distance by which the Node
should be moved.public Link getInLinkFrom(Node n)
n
- The sender node.public Link getOutLinkTo(Node n)
n
- The destination node.public Link getCommonLinkWith(Node n)
n
- The node at the opposite endpoint.public java.util.List<Link> getInLinks()
List
of inbound Link
s.public java.util.List<Link> getOutLinks()
List
of outbound Link
s.public java.util.List<Link> getLinks()
List
of Link
spublic java.util.List<Link> getLinks(boolean directed)
directed
- true for directed, false for
undirected. The returned list can be subsequently modified without
effect on the topology.List
of Link
spublic java.util.List<Node> getInNeighbors()
public java.util.List<Node> getOutNeighbors()
public java.util.List<Node> getSensedNodes()
public boolean hasNeighbors()
public java.util.List<Node> getNeighbors()
public java.util.List<Message> getMailbox()
List
of incoming Message
spublic java.util.List<Message> getOutbox()
List
of outgoing Message
spublic void send(Node destination, Message message)
destination
- The destination node.message
- The message to be sent.@Deprecated public void send(Node destination, java.lang.Object content)
send(Node, Message)
instead.destination
- The non-null destination.content
- The object to be sent.public void sendRetry(Node destination, Message message)
destination
- The non-null destination.message
- The message.@Deprecated public void sendRetry(Node destination, java.lang.Object content)
sendRetry(Node, Message)
instead.destination
- The non-null destination.content
- The object to be sent.public void sendAll(Message message)
message
- The message to be sent.@Deprecated public void sendAll(java.lang.Object content)
sendAll(Message)
instead.content
- The object to be sent.public double distance(Node n)
n
- The other node.public double distance(double x, double y)
x
- The abscissa of the point to which the distance is measured.y
- The ordinate of the point to which the distance is measured.public double distance(Point p)
p
- The location (as a 3D point).public double distance(double x, double y, double z)
x
- The abscissa of the point to which the distance is measured.y
- The ordinate of the point to which the distance is measured.z
- The applicate of the point to which the distance is measured.protected void notifyNodeMoved()
public int compareTo(Node o)
compareTo
in interface java.lang.Comparable<Node>
public java.lang.String toString()
toString
in class java.lang.Object