1: package GraphPackage; 2: import java.util.Iterator; 3: /** 4: An interface for a vertex in a graph. 5: 6: @author Frank M. Carrano 7: @author Timothy M. Henry 8: @version 5.0 9: */ 10: public interface VertexInterface<T> 11: { 12: /** Gets this vertex's label. 13: @return The object that labels the vertex. */ 14: public T getLabel(); 16: /** Marks this vertex as visited. */ 17: public void visit(); 19: /** Removes this vertex's visited mark. */ 20: public void unvisit(); 22: /** Sees whether the vertex is marked as visited. 23: @return True if the vertex is visited. */ 24: public boolean isVisited(); 26: /** Connects this vertex and a given vertex with a weighted edge. 27: The two vertices cannot be the same, and must not already 28: have this edge between them. In a directed graph, the edge 29: points toward the given vertex. 30: @param endVertex A vertex in the graph that ends the edge. 31: @param edgeWeight A real-valued edge weight, if any. 32: @return True if the edge is added, or false if not. */ 33: public boolean connect(VertexInterface<T> endVertex, double edgeWeight); 34: 35: /** Connects this vertex and a given vertex with an unweighted 36: edge. The two vertices cannot be the same, and must not 37: already have this edge between them. In a directed graph, 38: the edge points toward the given vertex. 39: @param endVertex A vertex in the graph that ends the edge. 40: @return True if the edge is added, or false if not. */ 41: public boolean connect(VertexInterface<T> endVertex); 43: /** Creates an iterator of this vertex's neighbors by following 44: all edges that begin at this vertex. 45: @return An iterator of the neighboring vertices of this vertex. */ 46: public Iterator<VertexInterface<T>> getNeighborIterator(); 48: /** Creates an iterator of the weights of the edges to this 49: vertex's neighbors. 50: @return An iterator of edge weights for edges to neighbors of this 51: vertex. */ 52: public Iterator<Double> getWeightIterator(); 54: /** Sees whether this vertex has at least one neighbor. 55: @return True if the vertex has a neighbor. */ 56: public boolean hasNeighbor(); 58: /** Gets an unvisited neighbor, if any, of this vertex. 59: @return Either a vertex that is an unvisited neighbor or null 60: if no such neighbor exists. */ 61: public VertexInterface<T> getUnvisitedNeighbor(); 63: /** Records the previous vertex on a path to this vertex. 64: @param predecessor The vertex previous to this one along a path. */ 65: public void setPredecessor(VertexInterface<T> predecessor); 67: /** Gets the recorded predecessor of this vertex. 68: @return Either this vertex's predecessor or null if no predecessor 69: was recorded. */ 70: public VertexInterface<T> getPredecessor(); 72: /** Sees whether a predecessor was recorded for this vertex. 73: @return True if a predecessor was recorded. */ 74: public boolean hasPredecessor(); 76: /** Records the cost of a path to this vertex. 77: @param newCost The cost of the path. */ 78: public void setCost(double newCost); 80: /** Gets the recorded cost of the path to this vertex. 81: @return The cost of the path. */ 82: public double getCost(); 83: } // end VertexInterface