edu.kzoo.grid
Class BoundedGrid.Array2DGridRep

java.lang.Object
  |
  +--edu.kzoo.grid.BoundedGrid.Array2DGridRep
All Implemented Interfaces:
Grid.InternalRepresentation
Enclosing class:
BoundedGrid

protected static class BoundedGrid.Array2DGridRep
extends java.lang.Object
implements Grid.InternalRepresentation

The Array2DGridRep class represents an internal bounded grid using a two-dimensional array.


Constructor Summary
BoundedGrid.Array2DGridRep(int rows, int cols)
          Constructs an empty Array2DGridRep representation with the given dimensions.
 
Method Summary
 void add(GridObject obj)
          Adds a new object to this internal grid representation at the location it specifies.
 GridObject[] allObjects()
          Returns all the objects in this grid.
 boolean isValid(Location loc)
          Verifies whether a location is valid in this grid.
 int numCols()
          Returns number of columns in this grid.
 int numObjects()
          Returns the number of objects in this grid.
 int numRows()
          Returns number of rows in this grid.
 GridObject objectAt(Location loc)
          Returns the object at a specific location in this grid.
 void remove(GridObject obj)
          Removes the object from this internal grid representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundedGrid.Array2DGridRep

public BoundedGrid.Array2DGridRep(int rows,
                                  int cols)
Constructs an empty Array2DGridRep representation with the given dimensions. (Precondition: rows > 0 and cols > 0.)

Parameters:
rows - number of rows in the grid
cols - number of columns in the grid
Method Detail

numRows

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

Returns:
the number of rows, or UNBOUNDED if the grid is unbounded

numCols

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

Returns:
the number of columns, or UNBOUNDED if the grid is unbounded

isValid

public boolean isValid(Location loc)
Verifies whether a location is valid in this grid.

Specified by:
isValid in interface Grid.InternalRepresentation
Parameters:
loc - location to check
Returns:
true if loc is valid; false otherwise

numObjects

public int numObjects()
Returns the number of objects in this grid.

Specified by:
numObjects in interface Grid.InternalRepresentation
Returns:
the number of objects

allObjects

public GridObject[] allObjects()
Returns all the objects in this grid.

Specified by:
allObjects in interface Grid.InternalRepresentation
Returns:
an array of all the grid objects

objectAt

public GridObject objectAt(Location loc)
Returns the object at a specific location in this grid.

Specified by:
objectAt in interface Grid.InternalRepresentation
Parameters:
loc - the location in which to look
Returns:
the object at location loc; null if loc is not in the grid or is empty

add

public void add(GridObject obj)
Adds a new object to this internal grid representation at the location it specifies. (Precondition: obj.grid() is this grid and obj.location() is a valid empty location; verified by the Grid object.)

Specified by:
add in interface Grid.InternalRepresentation
Parameters:
obj - the new object to be added

remove

public void remove(GridObject obj)
Removes the object from this internal grid representation. (Precondition: obj is in this grid; verified by the Grid object.)

Specified by:
remove in interface Grid.InternalRepresentation
Parameters:
obj - the object to be removed