public class BoundedGrid<E> extends AbstractGrid<E>
BoundedGrid is a rectangular grid with a finite number of
rows and columns. | Constructor and Description |
|---|
BoundedGrid(int rows,
int cols)
Constructs an empty bounded grid with the given dimensions.
|
| Modifier and Type | Method and Description |
|---|---|
E |
get(Location loc)
Returns the object at a given location in this grid.
|
int |
getNumCols()
Returns the number of columns in this grid.
|
int |
getNumRows()
Returns the number of rows in this grid.
|
ArrayList<Location> |
getOccupiedLocations()
Gets the locations in this grid that contain objects.
|
boolean |
isValid(Location loc)
Checks whether a location is valid in this grid.
|
E |
put(Location loc,
E obj)
Puts an object at a given location in this grid.
|
E |
remove(Location loc)
Removes the object at a given location from this grid.
|
getEmptyAdjacentLocations, getNeighbors, getOccupiedAdjacentLocations, getValidAdjacentLocations, toStringpublic BoundedGrid(int rows,
int cols)
rows > 0 and cols > 0.)rows - number of rows in BoundedGridcols - number of columns in BoundedGridpublic int getNumRows()
Gridpublic int getNumCols()
Gridpublic boolean isValid(Location loc)
Gridloc is not nullloc - the location to checktrue if loc is valid in this grid,
false otherwisepublic ArrayList<Location> getOccupiedLocations()
Gridpublic E get(Location loc)
Gridloc is valid in this gridloc - a location in this gridloc (or null
if the location is unoccupied)public E put(Location loc, E obj)
Gridloc is valid in this grid (2)
obj is not nullloc - the location at which to put the objectobj - the new object to be addedloc (or null
if the location was previously unoccupied)public E remove(Location loc)
Gridloc is valid in this gridloc - the location of the object that is to be removednull if the location
is unoccupied)