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 4.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();
15:
16: /** Marks this vertex as visited. */
17: public void visit();
18:
19: /** Removes this vertex's visited mark. */
20: public void unvisit();
21:
22: /** Sees whether the vertex is marked as visited.
23: @return True if the vertex is visited. */
24: public boolean isVisited();
25:
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);
42:
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();
47:
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();
53:
54: /** Sees whether this vertex has at least one neighbor.
55: @return True if the vertex has a neighbor. */
56: public boolean hasNeighbor();
57:
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();
62:
63: /** Records the previous vertex on a path to this vertex.
64: @param predecessor The vertex previous to this one along a path.
65: */
66: public void setPredecessor(VertexInterface<T> predecessor);
67:
68: /** Gets the recorded predecessor of this vertex.
69: @return Either this vertex's predecessor or null if no predecessor
70: was recorded. */
71: public VertexInterface<T> getPredecessor();
72:
73: /** Sees whether a predecessor was recorded for this vertex.
74: @return True if a predecessor was recorded. */
75: public boolean hasPredecessor();
76:
77: /** Records the cost of a path to this vertex.
78: @param newCost The cost of the path */
79: public void setCost(double newCost);
80:
81: /** Gets the recorded cost of the path to this vertex.
82: @return The cost of the path. */
83: public double getCost();
84: } // end VertexInterface