edu.kzoo.grid
Class ArrayListGrid.ArrayListGridRep

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

public static class ArrayListGrid.ArrayListGridRep
extends java.lang.Object
implements Grid.InternalRepresentation

Internal representation for an ArrayList-based implementation of a Grid class.


Constructor Summary
protected ArrayListGrid.ArrayListGridRep(Grid.ValidityChecker checker)
          Constructs an empty ArrayListGridRep representation of a grid.
 
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.
protected  int indexOf(Location loc)
          Get the index of the object at the specified location.
 boolean isValid(Location loc)
          Verifies whether a location is valid in this grid.
 int numObjects()
          Returns the number of objects 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

ArrayListGrid.ArrayListGridRep

protected ArrayListGrid.ArrayListGridRep(Grid.ValidityChecker checker)
Constructs an empty ArrayListGridRep representation of a grid.

Parameters:
checker - an object that knows how to check the validity of a location in a grid
Method Detail

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

indexOf

protected int indexOf(Location loc)
Get the index of the object at the specified location.

Parameters:
loc - the location in which to look
Returns:
the index of the object at location loc if there is one; -1 otherwise