Class Maze.MazeIterator

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

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

An iterator class that iterates over all the cells in a Maze. This class is implemented using the inner class language feature in Java which allows an inner (as opposed to nested) class to have an implicit reference to the containing class. Thus, any MazeIterator instance implicitly knows with which maze it is associated, and may access the maze's private fields.

Author:
Albert J. Wong (awong@cs)

Field Summary
private  int curCol
          Keeps track of the current column over which we are iterating.
private  int curRow
          Keeps track of the current row over which we are iterating.
 
Constructor Summary
private Maze.MazeIterator()
          Construct a new MazeIterator.
 
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

curRow

private int curRow
Keeps track of the current row over which we are iterating.


curCol

private int curCol
Keeps track of the current column over which we are iterating.

Constructor Detail

Maze.MazeIterator

private Maze.MazeIterator()
Construct a new MazeIterator.

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.