© 1998-2002 McGraw-Hill

structure
Class Vertex

java.lang.Object
  |
  +--structure.Vertex
Direct Known Subclasses:
GraphListVertex, GraphMatrixVertex

class Vertex
extends Object

A private implementation of a vertex for use in graphs. A vertex is capable of holding a label and has a flag that can be set to mark it as visited.

Typical Usage:

     Vertex v = new Vertex(someLabel);
     //...several graph related operations occur
     if(!v.isVisited()){
         Object label = v.label();
         v.visit();
     }
 

See Also:
GraphListVertex, GraphMatrixVertex

Field Summary
protected  Object label
          A label associated with vertex.
protected  boolean visited
          Whether or not a vertex has been visited.
 
Constructor Summary
Vertex(Object label)
          Construct a vertex with an associated label.
 
Method Summary
 boolean equals(Object o)
          Returns true iff the labels of two vertices are equal.
 int hashCode()
          Return a hashcode associated with the vertex.
 boolean isVisited()
          Determine if the vertex has been visited.
 Object label()
          Fetch the label associated with vertex.
 void reset()
          Clears the visited flag.
 String toString()
          Construct a string representing vertex.
 boolean visit()
          Test and set the visited flag.
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

label

protected Object label
A label associated with vertex.

visited

protected boolean visited
Whether or not a vertex has been visited.
Constructor Detail

Vertex

public Vertex(Object label)
Construct a vertex with an associated label.
Parameters:
label - A label to be associated with vertex.
Method Detail

label

public Object label()
Fetch the label associated with vertex.
Postcondition:
returns user label associated w/vertex
Returns:
The label associated with vertex.

visit

public boolean visit()
Test and set the visited flag.
Postcondition:
returns, then marks vertex as being visited
Returns:
The value of the flag before marking

isVisited

public boolean isVisited()
Determine if the vertex has been visited.
Postcondition:
returns true iff vertex has been visited
Returns:
True iff the vertex has been visited.

reset

public void reset()
Clears the visited flag.
Postcondition:
marks vertex unvisited

equals

public boolean equals(Object o)
Returns true iff the labels of two vertices are equal.
Overrides:
equals in class Object
Parameters:
o - Another vertex.
Postcondition:
returns true iff vertex labels are equal
Returns:
True iff the vertex labels are equal.

hashCode

public int hashCode()
Return a hashcode associated with the vertex.
Overrides:
hashCode in class Object
Postcondition:
returns hash code for vertex
Returns:
An integer for use in hashing values into tables.

toString

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

© 1998-2002 McGraw-Hill