com.collegeboard.gridworld.grid
Interface Grid<E>

All Known Implementing Classes:
BoundedGrid, UnboundedGrid

public interface Grid<E>


Method Summary
 E get(Location loc)
          Returns the object at a specific location 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.
 int numCols()
          Returns number of columns in this grid.
 int numRows()
          Returns number of rows in this grid.
 E put(Location loc, E obj)
          Adds a new object to this grid.
 E remove(Location loc)
          Removes an object from this grid.
 

Method Detail

numRows

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

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

numCols

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

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

put

E put(Location loc,
      E obj)
Adds a new object to this grid.

Parameters:
loc - the location at which to put the object (must be valid)
obj - the new object to be added (must not be null)
Returns:
the object that was removed, or null if the location was previously unoccupied.

remove

E remove(Location loc)
Removes an object from this grid.

Parameters:
loc - the location of the object that is to be removed (must be valid)
Returns:
the object that was removed, or null if no object was in the given location

get

E get(Location loc)
Returns the object at a specific location in this grid

Parameters:
loc - the location in which to look (must be valid)
Returns:
the object at location loc; null if loc is empty

getOccupiedLocations

ArrayList<Location> getOccupiedLocations()
Gets the locations in this grid that contain objects.

Returns:
an array of all occupied locations in this grid

isValid

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

Parameters:
loc - location to check (must not be null)
Returns:
true if loc is valid in this grid; false otherwise