edu.kzoo.grid
Class ArrayListGrid.Bounded

java.lang.Object
  |
  +--edu.kzoo.grid.Grid
        |
        +--edu.kzoo.grid.ArrayListGrid.Bounded
Enclosing class:
ArrayListGrid

public static class ArrayListGrid.Bounded
extends Grid

An ArrayListGrid.Bounded object is a rectangular, bounded two-dimensional container data structure implemented as an ArrayList of the objects it contains. It can contain any kind of object that can be modeled using an extension of the GridObject class. For example, a bounded grid could be used to model a board for a tic-tac-toe or chess game, an environment of fish for a marine biology simulation, etc.

ArrayListGrid.Bounded methods have the following time and space characteristics:
numObjectsO(1)
allObjectsO(n)
isEmpty, objectAtO(n)
addO(1) [amortized]
removeO(n)
spaceO(n)
where n is the number of objects in the grid.


Nested Class Summary
 
Nested classes inherited from class edu.kzoo.grid.Grid
Grid.BoundedGridValidityChecker, Grid.InternalRepresentation, Grid.UnboundedGridValidityChecker, Grid.ValidityChecker
 
Field Summary
 
Fields inherited from class edu.kzoo.grid.Grid
includeDiagonals, internalRep, UNBOUNDED
 
Constructor Summary
ArrayListGrid.Bounded(boolean includeDiagonalNeighbors, int rows, int cols)
          Constructs an empty ArrayListGrid.Bounded object with the given dimensions.
ArrayListGrid.Bounded(int rows, int cols)
          Constructs an empty ArrayListGrid.Bounded object with the given dimensions.
 
Method Summary
 int numCols()
          Returns number of columns in this grid.
 int numRows()
          Returns number of rows in this grid.
 
Methods inherited from class edu.kzoo.grid.Grid
add, allObjects, getDirection, getNeighbor, isEmpty, isValid, neighborsOf, numAdjacentNeighbors, numObjects, objectAt, randomDirection, remove, remove, removeAll, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayListGrid.Bounded

public ArrayListGrid.Bounded(int rows,
                             int cols)
Constructs an empty ArrayListGrid.Bounded object with the given dimensions. A cell's neighbors include only the cells to its north, south, east, and west, not the cells on the diagonals. (Precondition: rows > 0 and cols > 0.)

Parameters:
rows - number of rows in grid
cols - number of columns in grid
Throws:
java.lang.IllegalArgumentException - if the precondition is not met

ArrayListGrid.Bounded

public ArrayListGrid.Bounded(boolean includeDiagonalNeighbors,
                             int rows,
                             int cols)
Constructs an empty ArrayListGrid.Bounded object with the given dimensions. Each cell in this grid will have at most four or eight adjacent neighbors, depending on the value of the includeDiagonalNeighbors parameter. Cells along the grid boundaries will have fewer than the maximum four or eight neighbors. If includeDiagonalNeighbors is true, a cell's adjacent neighbors include the cells to its north, south, east, and west and the cells on the diagonals, to the northeast, southeast, northwest, and southwest. If includeDiagonalNeighbors is false, a cell's adjacent neighbors include only the four cells to its north, south, east, and west. (Precondition: rows > 0 and cols > 0.)

Parameters:
includeDiagonalNeighbors - whether to include the four diagonal locations as neighbors
rows - number of rows in grid
cols - number of columns in grid
Throws:
java.lang.IllegalArgumentException - if the precondition is not met
Method Detail

numRows

public int numRows()
Returns number of rows in this grid.

Specified by:
numRows in class Grid
Returns:
the number of rows in this grid

numCols

public int numCols()
Returns number of columns in this grid.

Specified by:
numCols in class Grid
Returns:
the number of columns in this grid