structure
Class Edge

java.lang.Object
  extended by structure.Edge
Direct Known Subclasses:
ComparableEdge

public class Edge
extends java.lang.Object

A class implementing common edge type among graphs. This class supports both directed and undirected edges. Edge may also have visited flags set and cleared.

See Also:
Graph

Field Summary
protected  boolean directed
          Whether or not this edge is directed.
protected  java.lang.Object label
          Label associated with edge.
protected  boolean visited
          Whether or not this edge has been visited.
protected  java.lang.Object[] vLabel
          Two element array of vertex labels.
 
Constructor Summary
Edge(java.lang.Object vtx1, java.lang.Object vtx2, java.lang.Object label, boolean directed)
          Construct a (possibly directed) edge between two labeled vertices.
 
Method Summary
 boolean equals(java.lang.Object o)
          Test for equality of edges.
 int hashCode()
          Returns hashcode associated with edge.
 java.lang.Object here()
          Returns the first vertex (or source if directed).
 boolean isDirected()
          Check to see if edge is directed.
 boolean isVisited()
          Check to see if edge has been visited.
 java.lang.Object label()
          Get label associated with edge.
 void reset()
          Clear the visited flag associated with edge.
 void setLabel(java.lang.Object label)
          Sets the label associated with the edge.
 java.lang.Object there()
          Returns the second vertex (or source if undirected).
 java.lang.String toString()
          Construct a string representation of edge.
 boolean visit()
          Test and set visited flag on vertex.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

vLabel

protected java.lang.Object[] vLabel
Two element array of vertex labels. When necessary, first element is source.


label

protected java.lang.Object label
Label associated with edge. May be null.


visited

protected boolean visited
Whether or not this edge has been visited.


directed

protected boolean directed
Whether or not this edge is directed.

Constructor Detail

Edge

public Edge(java.lang.Object vtx1,
            java.lang.Object vtx2,
            java.lang.Object label,
            boolean directed)
Construct a (possibly directed) edge between two labeled vertices. When edge is directed, vtx1 specifies source. When undirected, order of vertices is unimportant. Label on edge is any type, and may be null. Edge is initially unvisited.

Parameters:
vtx1 - The label of a vertex (source if directed).
vtx2 - The label of another vertex (destination if directed).
label - The label associated with the edge.
directed - True iff this edge is directed.
Postcondition:
edge associates vtx1 and vtx2; labeled with label directed if "directed" set true
Method Detail

here

public java.lang.Object here()
Returns the first vertex (or source if directed).

Returns:
A vertex; if directed, the source.
Postcondition:
returns first node in edge

there

public java.lang.Object there()
Returns the second vertex (or source if undirected).

Returns:
A vertex; if directed, the destination.
Postcondition:
returns second node in edge

setLabel

public void setLabel(java.lang.Object label)
Sets the label associated with the edge. May be null.

Parameters:
label - Any object to label edge, or null.
Postcondition:
sets label of this edge to label

label

public java.lang.Object label()
Get label associated with edge.

Returns:
The label found on the edge.
Postcondition:
returns label associated with this edge

visit

public boolean visit()
Test and set visited flag on vertex.

Returns:
True iff edge was visited previously.
Postcondition:
visits edge, returns whether previously visited

isVisited

public boolean isVisited()
Check to see if edge has been visited.

Returns:
True iff the edge has been visited.
Postcondition:
returns true iff edge has been visited

isDirected

public boolean isDirected()
Check to see if edge is directed.

Returns:
True iff the edge has been visited.
Postcondition:
returns true iff edge is directed

reset

public void reset()
Clear the visited flag associated with edge.

Postcondition:
resets edge's visited flag to initial state

hashCode

public int hashCode()
Returns hashcode associated with edge.

Overrides:
hashCode in class java.lang.Object
Returns:
An integer code suitable for hashing.
Postcondition:
returns suitable hashcode

equals

public boolean equals(java.lang.Object o)
Test for equality of edges. Undirected edges are equal if they connect the same vertices. Directed edges must have same direction.

Overrides:
equals in class java.lang.Object
Parameters:
o - The other edge.
Returns:
True iff this edge is equal to other edge.
Postcondition:
returns true iff edges connect same vertices

toString

public java.lang.String toString()
Construct a string representation of edge.

Overrides:
toString in class java.lang.Object
Returns:
String representing edge.
Postcondition:
returns string representation of edge