public static class ArrayListGrid.ArrayListGridRep extends java.lang.Object implements Grid.InternalRepresentation
ArrayList
-based
implementation of a Grid
class.Modifier | Constructor and Description |
---|---|
protected |
ArrayListGridRep(Grid.ValidityChecker checker)
Constructs an empty ArrayListGridRep representation of a grid.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected ArrayListGridRep(Grid.ValidityChecker checker)
checker
- an object that knows how to check the validity
of a location in a gridpublic boolean isValid(Location loc)
isValid
in interface Grid.InternalRepresentation
loc
- location to checktrue
if loc
is valid;
false
otherwisepublic int numObjects()
numObjects
in interface Grid.InternalRepresentation
public GridObject[] allObjects()
allObjects
in interface Grid.InternalRepresentation
public GridObject objectAt(Location loc)
objectAt
in interface Grid.InternalRepresentation
loc
- the location in which to lookloc
;
null
if loc
is not
in the grid or is emptypublic void add(GridObject obj)
obj.grid()
is this grid and
obj.location()
is a valid empty location;
verified by the Grid
object.)add
in interface Grid.InternalRepresentation
obj
- the new object to be addedpublic void remove(GridObject obj)
obj
is in this grid; verified
by the Grid
object.)remove
in interface Grid.InternalRepresentation
obj
- the object to be removedprotected int indexOf(Location loc)
loc
- the location in which to lookloc
if there is one; -1 otherwise