info.gridworld.grid
Class AbstractGrid<E>

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

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

This class contains the methods that are common to all grid implementations.

copyright© 2005 Cay S. Horstmann (http://horstmann.com)

Author:
Cay Horstmann

Constructor Summary
AbstractGrid()
           
 
Method Summary
 ArrayList<Location> getEmptyNeighborLocations(Location loc)
          Gets the locations of the empty neighbors in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)
 ArrayList<E> getNeighbors(Location loc)
          Gets the neighboring occupants in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)
 ArrayList<Location> getOccupiedNeighborLocations(Location loc)
          Gets the locations of the occupied neighbors in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)
 ArrayList<Location> getValidNeighborLocations(Location loc)
          Gets the valid locations of the neighbors in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)
 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 info.gridworld.grid.Grid
get, getOccupiedLocations, isValid, numCols, numRows, put, remove
 

Constructor Detail

AbstractGrid

public AbstractGrid()
Method Detail

getValidNeighborLocations

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

Specified by:
getValidNeighborLocations in interface Grid<E>
Parameters:
loc - a location in the grid
Returns:
an array list of the valid locations of loc in all eight directions

getEmptyNeighborLocations

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

Specified by:
getEmptyNeighborLocations in interface Grid<E>
Parameters:
loc - a location in the grid
Returns:
an array list of the empty locations of loc in all eight directions

getOccupiedNeighborLocations

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

Specified by:
getOccupiedNeighborLocations in interface Grid<E>
Parameters:
loc - a location in the grid
Returns:
an array list of the occupied locations of loc in all eight directions

getNeighbors

public ArrayList<E> getNeighbors(Location loc)
Gets the neighboring occupants in all directions (north, northeast, east, southeast, south, southwest, west, and northwest)

Specified by:
getNeighbors in interface Grid<E>
Parameters:
loc - a location in the grid
Returns:
an array list of the neighboring occupants of loc in all eight directions

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