|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Grid<E>
Grid
provides an interface for a two-dimensional, grid-like
environment containing arbitrary objects.
This interface is testable on the AP CS A and AB exams.
Method Summary | |
---|---|
E |
get(Location loc)
Returns the object at a given location in this grid. |
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<E> |
getOccupants()
Gets the occupants in all locations in this grid. |
int |
getNumCols()
Returns the number of columns in this grid. |
int |
getNumRows()
Returns the number of rows in this grid. |
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> |
getOccupiedLocations()
Gets the locations in this grid that contain objects. |
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). |
boolean |
isValid(Location loc)
Checks whether a location is valid in this grid. |
boolean |
isEmpty(Location loc)
Checks whether a location is valid and empty in this grid. |
E |
put(Location loc,
E obj)
Puts an object at a given location in this grid. |
E |
remove(Location loc)
Removes the object at a given location from this grid. |
Method Detail |
---|
int getNumRows()
int getNumCols()
boolean isValid(Location loc)
loc
is not null
loc
- the location to check
true
if loc
is valid in this grid,
false
otherwiseboolean isEmpty(Location loc)
loc
is not null
loc
- the location to check
true
if loc
is valid and empty in this grid,
false
otherwiseE put(Location loc, E obj)
loc
is valid in this grid (2)
obj
is not null
loc
- the location at which to put the objectobj
- the new object to be added
loc
(or null
if the location was previously unoccupied)E remove(Location loc)
loc
is valid in this grid
loc
- the location of the object that is to be removed
null if the location
is unoccupied)
get
E get(Location loc)
- Returns the object at a given location in this grid.
Precondition: loc
is valid in this grid
- Parameters:
loc
- a location in this grid
- Returns:
- the object at location
loc
(or null
if the location is unoccupied)
getOccupiedLocations
ArrayList<Location> getOccupiedLocations()
- Gets the locations in this grid that contain objects.
- Returns:
- an array list of all occupied locations in this grid
getValidAdjacentLocations
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).
Precondition: loc
is valid in this grid
- Parameters:
loc
- a location in this grid
- Returns:
- an array list of the valid locations adjacent to
loc
in this grid
getEmptyAdjacentLocations
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).
Precondition: loc
is valid in this grid
- Parameters:
loc
- a location in this grid
- Returns:
- an array list of the valid empty locations adjacent to
loc
in this grid
getOccupiedAdjacentLocations
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).
Precondition: loc
is valid in this grid
- Parameters:
loc
- a location in this grid
- Returns:
- an array list of the valid occupied locations adjacent to
loc
 in this grid
getOccupants
ArrayList<E> getOccupants()
- Gets all occupants in this grid.
- Parameters:
loc
- a location in this grid
- Returns:
- returns an array list of the objects in all occupied locations
getNeighbors
ArrayList<E> getNeighbors(Location loc)
- 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
- 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
Overview
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD