Class Edge

java.lang.Object
  |
  +--Edge
All Implemented Interfaces:
java.lang.Cloneable

public class Edge
extends java.lang.Object
implements java.lang.Cloneable

This class represents a directed, labeled edge.

Author:
Dries.VanDyck@rug.ac.be

Constructor Summary
Edge(Edge e)
          Copy Constructor.
Edge(java.lang.String label, int tail, int head)
          Constructs an Edge with given label going from tail to head.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this Edge.
 boolean connects(int node)
          True if node is one of the nodes of this Edge.
 boolean equals(java.lang.Object obj)
          Two Edges are equal iff they have the same label and the same endpoints.
 int head()
          Returns the head of this Edge.
 void invert()
          Reverses the direction of this Edge.
 java.lang.String label()
          Returns the label of this Edge.
 int[] nodes()
          Returns the nodes from this Edge as an array containing {tail,head}.
 int otherNode(int node)
          Returns the node at the other side of node or -1 if the given node is no endpoint of this Edge.
 void setHead(int newhead)
          Sets the head to newhead.
 void setLabel(java.lang.String newlabel)
          Sets the label to newlabel.
 void setNodes(int[] newnodes)
          Sets the tail from this Edge to newnodes[0] and the head to newnodes[1].
 void setNodes(int newtail, int newhead)
          Sets the tail from this Edge to newtail and the head to newhead.
 void setTail(int newtail)
          Sets the tail to newtail.
 int tail()
          Returns the tail of this Edge.
 java.lang.String toString()
          Returns a string representation of this Edge in the format label = (tail,head).
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Edge

public Edge(java.lang.String label,
            int tail,
            int head)
Constructs an Edge with given label going from tail to head.

Parameters:
label - the label of the Edge
tail - the tail of the Edge
head - the head of the Edge

Edge

public Edge(Edge e)
Copy Constructor.

Parameters:
e - the Edge to be duplicated
Method Detail

label

public java.lang.String label()
Returns the label of this Edge.

Returns:
the label of this Edge

setLabel

public void setLabel(java.lang.String newlabel)
Sets the label to newlabel.

Parameters:
newlabel - the new label of this Edge

head

public int head()
Returns the head of this Edge.

Returns:
the head of this Edge

setHead

public void setHead(int newhead)
Sets the head to newhead.

Parameters:
newhead - the new head of this Edge

tail

public int tail()
Returns the tail of this Edge.

Returns:
the tail of this Edge

setTail

public void setTail(int newtail)
Sets the tail to newtail.

Parameters:
newtail - the new tail of this Edge

nodes

public int[] nodes()
Returns the nodes from this Edge as an array containing {tail,head}.

Returns:
{tail,head}

setNodes

public void setNodes(int newtail,
                     int newhead)
Sets the tail from this Edge to newtail and the head to newhead.

Parameters:
newtail - the new tail of this Edge
newhead - the new head of this Edge

setNodes

public void setNodes(int[] newnodes)
Sets the tail from this Edge to newnodes[0] and the head to newnodes[1].

Parameters:
newnodes - the new nodes of this Edge

connects

public boolean connects(int node)
True if node is one of the nodes of this Edge.

Parameters:
node - the node to be checked
Returns:
true if the specified node is one of the endnodes of this Edge

otherNode

public int otherNode(int node)
Returns the node at the other side of node or -1 if the given node is no endpoint of this Edge.

Parameters:
node - the node for which the other endpoint has to be returned
Returns:
the other endpoint of the specified node or -1 if the specified node is no endpoint of this Edge

invert

public void invert()
Reverses the direction of this Edge.


toString

public java.lang.String toString()
Returns a string representation of this Edge in the format label = (tail,head).

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this Edge

equals

public boolean equals(java.lang.Object obj)
Two Edges are equal iff they have the same label and the same endpoints.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to be checke for equality
Returns:
true if the specified object equals this Edge, false otherwise

clone

public java.lang.Object clone()
Returns a clone of this Edge.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this Edge