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

All Known Implementing Classes:
AbstractGrid, BoundedGrid, UnboundedGrid

public interface Grid<E>


Field Summary
static int EAST
           
static int FULL_CIRCLE
           
static int HALF_CIRCLE
           
static int HALF_LEFT
           
static int HALF_RIGHT
           
static int LEFT
           
static int NORTH
           
static int NORTHEAST
           
static int NORTHWEST
           
static int RIGHT
           
static int SOUTH
           
static int SOUTHEAST
           
static int SOUTHWEST
           
static int WEST
           
 
Method Summary
 E get(Location loc)
          Returns the object at a specific location in this grid (must be valid)
 ArrayList<Location> getAllNeighborLocations(Location loc)
          Gets the valid locations of the neighbors in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)
 ArrayList<Location> getMainNeighborLocations(Location loc)
          Gets the valid locations of the neighbors in the main directions (north, east, south, and west)
 Location getNeighborLocation(Location loc, int angle)
          Gets the location in the given direction, or null if there is no valid location in that direction.
 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.
 void put(Location loc, E obj)
          Adds a new object to this grid.
 E remove(Location loc)
          Removes an object from this grid.
 

Field Detail

RIGHT

static final int RIGHT
See Also:
Constant Field Values

HALF_RIGHT

static final int HALF_RIGHT
See Also:
Constant Field Values

LEFT

static final int LEFT
See Also:
Constant Field Values

HALF_LEFT

static final int HALF_LEFT
See Also:
Constant Field Values

HALF_CIRCLE

static final int HALF_CIRCLE
See Also:
Constant Field Values

FULL_CIRCLE

static final int FULL_CIRCLE
See Also:
Constant Field Values

NORTH

static final int NORTH
See Also:
Constant Field Values

EAST

static final int EAST
See Also:
Constant Field Values

SOUTH

static final int SOUTH
See Also:
Constant Field Values

WEST

static final int WEST
See Also:
Constant Field Values

NORTHEAST

static final int NORTHEAST
See Also:
Constant Field Values

SOUTHEAST

static final int SOUTHEAST
See Also:
Constant Field Values

SOUTHWEST

static final int SOUTHWEST
See Also:
Constant Field Values

NORTHWEST

static final int NORTHWEST
See Also:
Constant Field Values
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

void 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)

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 (must be valid)

Parameters:
loc - the location in which to look
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
Returns:
true if loc is valid; false otherwise

getNeighborLocation

Location getNeighborLocation(Location loc,
                             int angle)
Gets the location in the given direction, or null if there is no valid location in that direction.

Parameters:
angle - an angle (0 degrees = Grid.NORTH, 45 degrees = Grid.NORTHWEST, etc.)
Returns:
the neighbor location in the direction that is obtained by rounding angle to the nearest multiple of 45 degrees, or null if there is no valid location in that direction

getMainNeighborLocations

ArrayList<Location> getMainNeighborLocations(Location loc)
Gets the valid locations of the neighbors in the main directions (north, east, south, and west)

Parameters:
loc - the location that is queried for the neighbor locations
Returns:
an array list of the valid locations of loc in the four main directions

getAllNeighborLocations

ArrayList<Location> getAllNeighborLocations(Location loc)
Gets the valid locations of the neighbors in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)

Parameters:
loc - the location that is queried for the neighbor locations
Returns:
an array list of the valid locations of loc in all eight directions