edu.kzoo.grid
Class ArrayListGrid.Unbounded

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

public static class ArrayListGrid.Unbounded
extends Grid

An ArrayListGrid.Unounded object is an unbounded 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.Unbounded 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.Unbounded()
          Constructs an empty ArrayListGrid.Unbounded object.
ArrayListGrid.Unbounded(boolean includeDiagonalNeighbors)
          Constructs an empty ArrayListGrid.Unbounded object.
 
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.Unbounded

public ArrayListGrid.Unbounded()
Constructs an empty ArrayListGrid.Unbounded object. 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.)


ArrayListGrid.Unbounded

public ArrayListGrid.Unbounded(boolean includeDiagonalNeighbors)
Constructs an empty ArrayListGrid.Unbounded object. Each cell in this grid will have at most four or eight adjacent neighbors, depending on the value of the includeDiagonalNeighbors parameter. 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
Method Detail

numRows

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

Specified by:
numRows in class Grid
Returns:
the number of rows, or UNBOUNDED if the grid is unbounded

numCols

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

Specified by:
numCols in class Grid
Returns:
the number of columns, or UNBOUNDED if the grid is unbounded