WatorWorld
Class AbstractGrid<E>

java.lang.Object
  extended by WatorWorld.AbstractGrid<E>
All Implemented Interfaces:
Grid<E>
Direct Known Subclasses:
BoundedGrid

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

AbstractGrid contains the methods that are common to grid implementations.
The implementation of this class is testable on the AP CS AB exam.


Constructor Summary
AbstractGrid()
           
 
Method Summary
 ArrayList<Location> getEmptyAdjacentLocations(Location loc)
          Gets the valid empty locations adjacent to a given location in all eight compass directions (north, northeast, east, southeast, south, southwest, west, and northwest).
 ArrayList<E> getNeighbors(Location loc)
          Gets the neighboring occupants in all eight compass directions (north, northeast, east, southeast, south, southwest, west, and northwest).
 ArrayList<Location> getOccupiedAdjacentLocations(Location loc)
          Gets the valid occupied locations adjacent to a given location in all eight compass directions (north, northeast, east, southeast, south, southwest, west, and northwest).
 ArrayList<Location> getValidAdjacentLocations(Location loc)
          Gets the valid locations adjacent to a given location in all eight compass directions (north, northeast, east, southeast, south, southwest, west, and northwest).
 String toString()
          Creates a string that describes this grid.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface WatorWorld.Grid
get, getNumCols, getNumRows, getOccupiedLocations, isValid, put, remove
 

Constructor Detail

AbstractGrid

public AbstractGrid()
Method Detail

getNeighbors

public ArrayList<E> getNeighbors(Location loc)
Description copied from interface: Grid
Gets the neighboring occupants in all eight compass directions (north, northeast, east, southeast, south, southwest, west, and northwest).
Precondition: loc is valid in this grid

Specified by:
getNeighbors in interface Grid<E>
Parameters:
loc - a location in this grid
Returns:
returns an array list of the objects in the occupied locations adjacent to loc in this grid

getValidAdjacentLocations

public ArrayList<Location> getValidAdjacentLocations(Location loc)
Description copied from interface: Grid
Gets the valid locations adjacent to a given location in all eight compass directions (north, northeast, east, southeast, south, southwest, west, and northwest).
Precondition: loc is valid in this grid

Specified by:
getValidAdjacentLocations in interface Grid<E>
Parameters:
loc - a location in this grid
Returns:
an array list of the valid locations adjacent to loc in this grid

getEmptyAdjacentLocations

public ArrayList<Location> getEmptyAdjacentLocations(Location loc)
Description copied from interface: Grid
Gets the valid empty locations adjacent to a given location in all eight compass directions (north, northeast, east, southeast, south, southwest, west, and northwest).
Precondition: loc is valid in this grid

Specified by:
getEmptyAdjacentLocations in interface Grid<E>
Parameters:
loc - a location in this grid
Returns:
an array list of the valid empty locations adjacent to loc in this grid

getOccupiedAdjacentLocations

public ArrayList<Location> getOccupiedAdjacentLocations(Location loc)
Description copied from interface: Grid
Gets the valid occupied locations adjacent to a given location in all eight compass directions (north, northeast, east, southeast, south, southwest, west, and northwest).
Precondition: loc is valid in this grid

Specified by:
getOccupiedAdjacentLocations in interface Grid<E>
Parameters:
loc - a location in this grid
Returns:
an array list of the valid occupied locations adjacent to loc in this grid

toString

public String toString()
Creates a string that describes this grid.

Overrides:
toString in class Object
Returns:
a string with descriptions of all objects in this grid (not necessarily in any particular order), in the format {loc=obj, loc=obj, ...}