Class GridIterator

java.lang.Object
  |
  +--GridIterator
All Implemented Interfaces:
java.util.Iterator
Direct Known Subclasses:
ColMajorGridIterator, RowMajorGridIterator

public abstract class GridIterator
extends java.lang.Object
implements java.util.Iterator

Grid Iterator Lab:
A GridIterator object provides an iterator that that steps through the locations of a BoundedGrid object in a particular order.

GridIterator implementations need not support the remove method, as it does not make sense to remove locations from a bounded grid.

Version:
1 September 2002
Author:
Alyce Brady
See Also:
BoundedGrid, Location

Constructor Summary
GridIterator(edu.kzoo.grid.BoundedGrid grid)
          Constructs an iterator object that steps through a grid starting at location (0, 0).
GridIterator(edu.kzoo.grid.BoundedGrid grid, edu.kzoo.grid.Location startingLoc)
          Constructs an iterator object that steps through a grid, starting at a given location.
 
Method Summary
 edu.kzoo.grid.BoundedGrid grid()
          Returns grid through which this iterator iterates.
 boolean hasNext()
          Returns true if the grid has more locations.
 java.lang.Object next()
          Returns the next location in the grid.
 void remove()
          Removes from the underlying collection the last element returned by the iterator (not supported).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridIterator

public GridIterator(edu.kzoo.grid.BoundedGrid grid)
Constructs an iterator object that steps through a grid starting at location (0, 0).

Parameters:
grid - grid to iterate through

GridIterator

public GridIterator(edu.kzoo.grid.BoundedGrid grid,
                    edu.kzoo.grid.Location startingLoc)
Constructs an iterator object that steps through a grid, starting at a given location.

Parameters:
grid - grid to iterate through
startingLoc - where to start the iteration
Method Detail

grid

public edu.kzoo.grid.BoundedGrid grid()
Returns grid through which this iterator iterates.


hasNext

public boolean hasNext()
Returns true if the grid has more locations.

Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Returns the next location in the grid.

Specified by:
next in interface java.util.Iterator

remove

public void remove()
Removes from the underlying collection the last element returned by the iterator (not supported).

Specified by:
remove in interface java.util.Iterator