Class Maze.NeighborIterator

java.lang.Object
  extended by Maze.NeighborIterator
All Implemented Interfaces:
java.util.Iterator<MazeCell>
Enclosing class:
Maze

private class Maze.NeighborIterator
extends java.lang.Object
implements java.util.Iterator<MazeCell>

An iterator class that iterates over all neighbors that can be reached from the cell the iterator was created for. As for MazeIterator, we use an inner class so that NeighborIterator is associated with a particular instance of Maze.

Author:
Albert J. Wong (awong@cs)

Field Summary
private  Direction curWall
          The current wall we are examining.
private  int numNeighborsFound
          The number of neighbors we have found for this cell so far.
private  MazeCell refCell
          The cell over whose neighbors we are iterating.
 
Constructor Summary
Maze.NeighborIterator(MazeCell cell)
          Construct a new NeighborIterator that will iterator over the neighbors of cell
 
Method Summary
 boolean hasNext()
          Returns true if there are still cells to be iterated over, false otherwise.
 MazeCell next()
          If hasNext() is true, this returns the next cell in the iteration sequence.
 void remove()
          The remove function is not implemented in this iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

refCell

private MazeCell refCell
The cell over whose neighbors we are iterating.


curWall

private Direction curWall
The current wall we are examining.


numNeighborsFound

private int numNeighborsFound
The number of neighbors we have found for this cell so far.

Constructor Detail

Maze.NeighborIterator

public Maze.NeighborIterator(MazeCell cell)
Construct a new NeighborIterator that will iterator over the neighbors of cell

Parameters:
cell - The cell whose neighbors this iterator will iterate over.
Method Detail

hasNext

public boolean hasNext()
Returns true if there are still cells to be iterated over, false otherwise.

Specified by:
hasNext in interface java.util.Iterator<MazeCell>
Returns:
true if there are still cells to be iterated over, false otherwise.

next

public MazeCell next()
If hasNext() is true, this returns the next cell in the iteration sequence. Otherwise a NoSuchElementException is thrown.

Specified by:
next in interface java.util.Iterator<MazeCell>
Returns:
the next cell in the iteration sequence
Throws:
java.util.NoSuchElementException - Thrown if next() is called when there are no more elements to be iterated over.

remove

public void remove()
The remove function is not implemented in this iterator.

Specified by:
remove in interface java.util.Iterator<MazeCell>
Throws:
java.lang.UnsupportedOperationException - Thrown when remove() is called.