public class Link extends Properties implements Comparable<Link>
The Link
object encodes a communication link between two Node
s.
Links can either be Link.Orientation.DIRECTED
or Link.Orientation.UNDIRECTED
, and either
Link.Mode.WIRED
or Link.Mode.WIRELESS
.
The by default, a link will be Link.Orientation.UNDIRECTED
and Link.Mode.WIRELESS
.
Modifier and Type | Class and Description |
---|---|
static class |
Link.Mode
Enumerates the two possible modes of a link:
Mode.WIRED and
Mode.WIRELESS . |
static class |
Link.Orientation
Enumerates the two possible types of a link:
Orientation.DIRECTED and
Orientation.UNDIRECTED . |
Modifier and Type | Field and Description |
---|---|
static Color |
DEFAULT_COLOR |
static Link.Mode |
DEFAULT_MODE |
static Link.Orientation |
DEFAULT_ORIENTATION |
static int |
DEFAULT_WIDTH |
Node |
destination
The destination node of this link (if directed),
the second endpoint otherwise.
|
Link.Mode |
mode
The
Mode of this link (wired/wireless) |
Link.Orientation |
orientation
The
Orientation of this link (directed/undirected) |
Node |
source
The source node of this link (if directed),
the first endpoint otherwise.
|
properties
Constructor and Description |
---|
Link(Node n1,
Node n2)
Creates an undirected wired link between the two specified nodes.
|
Link(Node from,
Node to,
Link.Mode mode)
Creates a link with the specified
mode between the nodes
from and to . |
Link(Node from,
Node to,
Link.Orientation orientation)
Creates a wired link of the specified
orientation between the nodes
from and to . |
Link(Node from,
Node to,
Link.Orientation orientation,
Link.Mode mode)
Creates a link of the specified
orientation with the specified
mode between the nodes from and to. |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Link l)
Compares the specified link to this link in terms of length.
|
Node |
endpoint(int index)
Returns the requested endpoint node of this link
|
List<Node> |
endpoints()
Returns an list containing the two endpoint nodes of this link
|
boolean |
equals(Object o)
Compares the specified object with this link for equality.
|
Color |
getColor()
Returns the color of this link.
|
Double |
getLength()
Returns the euclidean distance between this link endpoints.
|
Node |
getOtherEndpoint(Node n)
Returns the node located at the opposite of the specified node
(reference node) on the underlying link.
|
Topology |
getTopology()
Returns the parent topology of this link, if any.
|
Integer |
getWidth()
Returns the width of this link.
|
boolean |
isDirected()
Tests whether the
orientation is DIRECTED. |
boolean |
isWireless()
Tests whether the
mode is WIRELESS. |
void |
setColor(Color color)
Sets the color of this link
|
void |
setWidth(Integer width)
Sets the width of this link.
|
String |
toString()
Returns a string representation of this link.
|
addPropertyListener, getProperty, hasProperty, removeProperty, removePropertyListener, setProperty
public static final Color DEFAULT_COLOR
public static final int DEFAULT_WIDTH
public static final Link.Orientation DEFAULT_ORIENTATION
public static final Link.Mode DEFAULT_MODE
public Node source
public Node destination
public Link.Orientation orientation
Orientation
of this link (directed/undirected)public Link.Mode mode
Mode
of this link (wired/wireless)public Link(Node n1, Node n2)
n1
- The source node.n2
- The destination node.public Link(Node from, Node to, Link.Orientation orientation)
orientation
between the nodes
from
and to
. The respective order of from
and to
does not matter if the specified orientation is undirected.from
- The source node.to
- The destination node.orientation
- The orientation of the link (Orientation.DIRECTED
or
Orientatino.UNDIRECTED
).public Link(Node from, Node to, Link.Mode mode)
mode
between the nodes
from
and to
. The created link is undirected by
default. The respective order of from
and to
does not
matter.from
- The source node.to
- The destination node.mode
- The mode of the link (Mode.WIRED
or
Mode.WIRELESS
).public Link(Node from, Node to, Link.Orientation orientation, Link.Mode mode)
orientation
with the specified
mode
between the nodes from and to. The created link is wired
by default. The respective order of from
and to
does
not matter if the orientation is undirected.from
- The source node.to
- The destination node.orientation
- The orientation of the link (Orientation.DIRECTED
or
Orientation.UNDIRECTED
).mode
- The mode of the link (Mode.WIRED
or
Mode.WIRELESS
).public List<Node> endpoints()
public Node endpoint(int index)
index
- The endpoint index (0 or 1).public Node getOtherEndpoint(Node n)
n
- The reference node.public Topology getTopology()
null
if the link has none.public void setColor(Color color)
color
- the new Color
of the link.public Integer getWidth()
public void setWidth(Integer width)
width
- the width of this link.public Double getLength()
Double
.public boolean isWireless()
mode
is WIRELESS.true
if the link mode
is WIRELESS,
false
otherwise.public boolean isDirected()
orientation
is DIRECTED.true
if the link orientation
is DIRECTED,
false
otherwise.public boolean equals(Object o)
true
if both links have the same orientation
(directed/undirected) and the same endpoints (interchangeably if
undirected). The mode
is not considered by the equality test.public int compareTo(Link l)
compareTo
in interface Comparable<Link>