1: // @author Frank M. Carrano, Timothy M. Henry
2: // @version 5.0
3: public boolean connect(VertexInterface<T> endVertex, double edgeWeight)
4: {
5: boolean result = false;
7: if (!this.equals(endVertex))
8: { // Vertices are distinct
9: Iterator<VertexInterface<T>> neighbors = getNeighborIterator();
10: boolean duplicateEdge = false;
12: while (!duplicateEdge && neighbors.hasNext())
13: {
14: VertexInterface<T> nextNeighbor = neighbors.next();
15: if (endVertex.equals(nextNeighbor))
16: duplicateEdge = true;
17: } // end while
19: if (!duplicateEdge)
20: {
21: edgeList.add(new Edge(endVertex, edgeWeight));
22: result = true;
23: } // end if
24: } // end if
26: return result;
27: } // end connect
29: public boolean connect(VertexInterface<T> endVertex)
30: {
31: return connect(endVertex, 0);
32: } // end connect