© 1998-2002 McGraw-Hill

structure
Class Edge

java.lang.Object
  |
  +--structure.Edge
Direct Known Subclasses:
ComparableEdge

public class Edge
extends 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.

Typical usage:

     Graph g = new GraphListDirected();
     g.add("harry");
     g.add("sally");
     g.addEdge("harry","sally","friendly");
     Edge e = g.getEdge("harry","sally");
     Object label = e.label();
     if(e.isDirected()){
          Vertex source = e.here();
          Vertex destination = e.there();
     }
     e.visit();
     e.reset();
     ...
 

See Also:
Graph

Field Summary
protected  boolean directed
          Whether or not this edge is directed.
protected  Object label
          Label associated with edge.
protected  boolean visited
          Whether or not this edge has been visited.
protected  Object[] vLabel
          Two element array of vertex labels.
 
Constructor Summary
Edge(Object vtx1, Object vtx2, Object label, boolean directed)
          Construct a (possibly directed) edge between two labeled vertices.
 
Method Summary
 boolean equals(Object o)
          Test for equality of edges.
 int hashCode()
          Returns hashcode associated with edge.
 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.
 Object label()
          Get label associated with edge.
 void reset()
          Clear the visited flag associated with edge.
 void setLabel(Object label)
          Sets the label associated with the edge.
 Object there()
          Returns the second vertex (or source if undirected).
 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, registerNatives, wait, wait, wait
 

Field Detail

vLabel

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

label

protected 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(Object vtx1,
            Object vtx2,
            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.
Method Detail

here

public Object here()
Returns the first vertex (or source if directed).
Postcondition:
returns first node in edge
Returns:
A vertex; if directed, the source.

there

public Object there()
Returns the second vertex (or source if undirected).
Postcondition:
returns second node in edge
Returns:
A vertex; if directed, the destination.

setLabel

public void setLabel(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 Object label()
Get label associated with edge.
Postcondition:
returns label associated with this edge
Returns:
The label found on the edge.

visit

public boolean visit()
Test and set visited flag on vertex.
Postcondition:
visits edge, returns whether previously visited
Returns:
True iff edge was visited previously.

isVisited

public boolean isVisited()
Check to see if edge has been visited.
Postcondition:
returns true iff edge has been visited
Returns:
True iff the edge has been visited.

isDirected

public boolean isDirected()
Check to see if edge is directed.
Postcondition:
returns true iff edge is directed
Returns:
True iff the edge has been visited.

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 Object
Postcondition:
returns suitable hashcode
Returns:
An integer code suitable for hashing.

equals

public boolean equals(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 Object
Parameters:
o - The other edge.
Postcondition:
returns true iff edges connect same vertices
Returns:
True iff this edge is equal to other edge.

toString

public String toString()
Construct a string representation of edge.
Overrides:
toString in class Object
Postcondition:
returns string representation of edge
Returns:
String representing edge.

© 1998-2002 McGraw-Hill