Source of 30.13.java


  1: // @author Frank M. Carrano, Timothy M. Henry
  2: // @version 5.0
  3: public Iterator<VertexInterface<T>> getNeighborIterator()
  4: {
  5:    return new NeighborIterator();
  6: } // end getNeighborIterator

  8: private class NeighborIterator implements Iterator<VertexInterface<T>>
  9: {
 10:    private Iterator<Edge> edges;
 11:    
 12:    private NeighborIterator()
 13:    {
 14:       edges = edgeList.getIterator();
 15:    } // end default constructor
 16:    
 17:    public boolean hasNext()
 18:    {
 19:       return edges.hasNext();
 20:    } // end hasNext
 21:    
 22:    public VertexInterface<T> next()
 23:    {
 24:       VertexInterface<T> nextNeighbor = null;
 25:       
 26:       if (edges.hasNext())
 27:       {
 28:          Edge edgeToNextNeighbor = edges.next();
 29:          nextNeighbor = edgeToNextNeighbor.getEndVertex();
 30:       }
 31:       else
 32:          throw new NoSuchElementException();
 33:       
 34:       return nextNeighbor;
 35:    } // end next
 36:    
 37:    public void remove()
 38:    {
 39:       throw new UnsupportedOperationException();
 40:    } // end remove
 41: } // end NeighborIterator