com.collegeboard.gridworld.grid
Class AbstractGrid<E>

java.lang.Object
  extended by com.collegeboard.gridworld.grid.AbstractGrid<E>
All Implemented Interfaces:
Grid<E>
Direct Known Subclasses:
BoundedGrid, UnboundedGrid

public abstract class AbstractGrid<E>
extends Object
implements Grid<E>


Field Summary
 
Fields inherited from interface com.collegeboard.gridworld.grid.Grid
EAST, FULL_CIRCLE, HALF_CIRCLE, HALF_LEFT, HALF_RIGHT, LEFT, NORTH, NORTHEAST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHWEST, WEST
 
Constructor Summary
AbstractGrid()
           
 
Method Summary
 ArrayList<Location> getAllNeighborLocations(Location ofLoc)
          Gets the valid locations of the neighbors in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)
 ArrayList<Location> getMainNeighborLocations(Location ofLoc)
          Gets the valid locations of the neighbors in the main directions (north, east, south, and west)
 Location getNeighborLocation(Location fromLoc, int direction)
          Gets the location in the given direction, or null if there is no valid location in that direction.
 boolean isValid(Location loc)
          Checks whether a location is valid in this grid.
 String toString()
          Creates a string representing all the objects in this grid (not necessarily in any particular order).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.collegeboard.gridworld.grid.Grid
get, getOccupiedLocations, numCols, numRows, put, remove
 

Constructor Detail

AbstractGrid

public AbstractGrid()
Method Detail

isValid

public boolean isValid(Location loc)
Description copied from interface: Grid
Checks whether a location is valid in this grid.

Specified by:
isValid in interface Grid<E>
Parameters:
loc - location to check
Returns:
true if loc is valid; false otherwise

toString

public String toString()
Creates a string representing all the objects in this grid (not necessarily in any particular order).

Overrides:
toString in class Object
Returns:
a string indicating all the objects in this environment

getNeighborLocation

public Location getNeighborLocation(Location fromLoc,
                                    int direction)
Description copied from interface: Grid
Gets the location in the given direction, or null if there is no valid location in that direction.

Specified by:
getNeighborLocation in interface Grid<E>
direction - 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

public ArrayList<Location> getMainNeighborLocations(Location ofLoc)
Description copied from interface: Grid
Gets the valid locations of the neighbors in the main directions (north, east, south, and west)

Specified by:
getMainNeighborLocations in interface Grid<E>
Parameters:
ofLoc - 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

public ArrayList<Location> getAllNeighborLocations(Location ofLoc)
Description copied from interface: Grid
Gets the valid locations of the neighbors in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)

Specified by:
getAllNeighborLocations in interface Grid<E>
Parameters:
ofLoc - the location that is queried for the neighbor locations
Returns:
an array list of the valid locations of loc in all eight directions