netkit.graph
Class Edge

java.lang.Object
  extended by netkit.graph.Edge
All Implemented Interfaces:
java.lang.Comparable<Edge>

public final class Edge
extends java.lang.Object
implements java.lang.Comparable<Edge>

The Edge class represents an edge in the Graph object. It connects a source and destination Node with a given weight. Edges also have an EdgeType which specifies which kinds of Nodes can be connected by this Edge.

Author:
Kaveh R. Ghazi
See Also:
Graph, Node, EdgeType, Attributes, SchemaReader

Constructor Summary
Edge(Edge e)
          Copy constructor
Edge(EdgeType edgeType, Node source, Node dest, double weight)
          The constructor requires an EdgeType, a source and destination Node and a weight.
 
Method Summary
 void addWeight(double weight)
          Increments the weight field of this Edge.
 int compareTo(Edge e)
          Specifies a natural ordering for Edges; compare EdgeTypes first, then the source Node and finally the destination Node.
 boolean equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this one.
 Node getDest()
          Get the destination node of this object.
 EdgeType getEdgeType()
          Get the edge type of this object.
 Node getSource()
          Get the source node of this object.
 double getWeight()
          Get the weight field of this object.
 int hashCode()
          Returns a hash code value for this object.
 void setWeight(double weight)
          Sets the weight field of this Edge.
 java.lang.String toString()
          Returns a String representation for this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Edge

public Edge(EdgeType edgeType,
            Node source,
            Node dest,
            double weight)
The constructor requires an EdgeType, a source and destination Node and a weight.

Parameters:
edgeType - an edge type describing the valid node types of the source and destination nodes.
source - a node whose type must be valid for the EdgeType.
dest - a node whose type must be valid for the EdgeType.
weight - a double value representing the weight of this edge.
Throws:
java.lang.RuntimeException - if the source or dest Node's node type is not valid for the supplied EdgeType.
java.lang.IllegalArgumentException - if the supplied weight increment is less than zero.

Edge

public Edge(Edge e)
Copy constructor

Parameters:
e - an Edge to copy into a new object.
Method Detail

addWeight

public void addWeight(double weight)
Increments the weight field of this Edge.

Parameters:
weight - the amount by which the weight is incremented.
Throws:
java.lang.IllegalArgumentException - if the supplied weight increment is less than zero.

setWeight

public void setWeight(double weight)
Sets the weight field of this Edge.

Parameters:
weight - the new weight of the edge.
Throws:
java.lang.IllegalArgumentException - if the supplied weight is less than zero.

getWeight

public double getWeight()
Get the weight field of this object.

Returns:
the weight field of this object.

getSource

public Node getSource()
Get the source node of this object.

Returns:
the source node of this object.

getDest

public Node getDest()
Get the destination node of this object.

Returns:
the destination node of this object.

getEdgeType

public EdgeType getEdgeType()
Get the edge type of this object.

Returns:
the edge type of this object.

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.

equals

public boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the argument; false otherwise.

compareTo

public int compareTo(Edge e)
Specifies a natural ordering for Edges; compare EdgeTypes first, then the source Node and finally the destination Node.

Specified by:
compareTo in interface java.lang.Comparable<Edge>
Parameters:
e - the Edge to compare this object to.
Returns:
a natural ordering for Edges; compare EdgeTypes first, then the source Node and finally the destination Node.

toString

public java.lang.String toString()
Returns a String representation for this object.

Overrides:
toString in class java.lang.Object
Returns:
a String representation for this object.