Class Grid

java.lang.Object
  |
  +--Grid
Direct Known Subclasses:
AppletGrid

class Grid
extends java.lang.Object


Field Summary
(package private) static int BLANK
          value for the blank character
(package private) static int BLOCKAGE
          value for a blockage character
protected  int cols
          the number of columns of the Grid
(package private) static int DESCbody
          value for the DESC body character (used in a07)
(package private) static int DESChead
          value for the DESC head character (used in a07)
protected  int rows
          the number of rows of the Grid
(package private) static int SPAM
          value for the spam character
protected  Square[][] square
          the Squares of the Grid
 
Constructor Summary
(package private) Grid(int rows, int cols)
          Construct a grid of a given size.
(package private) Grid(Sample sample)
          Construct a grid from a Sample, which includes the relevant size information and spam settins.
 
Method Summary
(package private)  boolean clear(Pair pair)
          Set the contents of a Square to blank
(package private)  void clearParents()
          Clear all parents in preparation for a search.
(package private)  boolean contains(int row, int col, int v)
          Determine whether a Square contains specified contents.
(package private)  int get(int row, int col)
          Get the contents of a Square
(package private)  Pair getParent(Pair pair)
          Get the parent of a Square located at a particular Pair of coordinates.
(package private)  Square getSquare(Pair pair)
          Get the Square located at a particular Pair of coordinates.
 boolean hasDESC(int row, int col)
          Check whether a Square has a DESC end or body cell.
 boolean hasDESCbody(int row, int col)
          Check whether a Square has a DESC body cell.
 boolean hasDESCend(int row, int col)
          Check whether a Square has a DESC end cell.
 boolean hasSpam(int row, int col)
          Indicate whether a particular Square has spam.
(package private)  void initialize()
          Construct the Squares of the Grid and initialize them.
(package private)  boolean inRange(int row, int col)
          Check whether a Square is within the Grid.
 boolean isBlank(int row, int col)
          Indicate whether a particular Square is blank.
(package private)  boolean isBlocked(int row, int col)
          Determine whether a Square has a blockage
(package private)  boolean isMarked(int row, int col)
          Determine whether a Square has been visited during a search
(package private)  boolean set(int row, int col, int v)
          Set the contents of a Square, after first checking that it is in range.
(package private)  boolean set(Pair pair, int v)
          Set the contents of a Square, after first checking that it is in range.
 boolean setBlank(int row, int col)
          Make a Square of the grid blank.
 void setList(java.util.Enumeration pairs, int value)
          Set value on squares indexed by Pairs from an enumeration.
(package private)  void setParent(int row, int col, Pair parent)
          Set coordinates of the parent of a Square
(package private)  void setParent(Pair current, Pair parent)
          Set coordinates of the parent of a Square
 boolean setToBody(Pair pair)
          Set a Square of show a DESC body.
 boolean setToEnd(Pair pair)
          Set a Square of show a DESC end.
 java.lang.String toString()
          Return a String representation of this Grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BLANK

static final int BLANK
value for the blank character

See Also:
Constant Field Values

SPAM

static final int SPAM
value for the spam character

See Also:
Constant Field Values

BLOCKAGE

static final int BLOCKAGE
value for a blockage character

See Also:
Constant Field Values

DESChead

static final int DESChead
value for the DESC head character (used in a07)

See Also:
Constant Field Values

DESCbody

static final int DESCbody
value for the DESC body character (used in a07)

See Also:
Constant Field Values

rows

protected int rows
the number of rows of the Grid


cols

protected int cols
the number of columns of the Grid


square

protected Square[][] square
the Squares of the Grid

Constructor Detail

Grid

Grid(int rows,
     int cols)
Construct a grid of a given size.

Parameters:
rows - the number of rows
cols - the number of columns

Grid

Grid(Sample sample)
Construct a grid from a Sample, which includes the relevant size information and spam settins.

Parameters:
sample - the Sample specifying Grid size and contents
Method Detail

setList

public void setList(java.util.Enumeration pairs,
                    int value)
Set value on squares indexed by Pairs from an enumeration.

Parameters:
pairs - the enumeration of Pairs given

hasSpam

public boolean hasSpam(int row,
                       int col)
Indicate whether a particular Square has spam.

Parameters:
row - row to be checked
col - column to be checked

setBlank

public boolean setBlank(int row,
                        int col)
Make a Square of the grid blank.

Parameters:
row - row of the Square
col - column of the Square

setToEnd

public boolean setToEnd(Pair pair)
Set a Square of show a DESC end.


setToBody

public boolean setToBody(Pair pair)
Set a Square of show a DESC body.


inRange

boolean inRange(int row,
                int col)
Check whether a Square is within the Grid.

Parameters:
row - row of the Square
col - column of the Square

hasDESC

public boolean hasDESC(int row,
                       int col)
Check whether a Square has a DESC end or body cell.

Parameters:
row - row of the Square
col - column of the Square

hasDESCend

public boolean hasDESCend(int row,
                          int col)
Check whether a Square has a DESC end cell.

Parameters:
row - row of the Square
col - column of the Square

hasDESCbody

public boolean hasDESCbody(int row,
                           int col)
Check whether a Square has a DESC body cell.

Parameters:
row - row of the Square
col - column of the Square

isBlank

public boolean isBlank(int row,
                       int col)
Indicate whether a particular Square is blank.

Parameters:
row - row to be checked
col - column to be checked

get

int get(int row,
        int col)
Get the contents of a Square

Parameters:
row - row of the Square
col - column of the Square
Returns:
contents of the Sqaure

set

boolean set(int row,
            int col,
            int v)
Set the contents of a Square, after first checking that it is in range.

Parameters:
row - row of the Square
col - column of the Square
Returns:
whether setting was done

set

boolean set(Pair pair,
            int v)
Set the contents of a Square, after first checking that it is in range.

Parameters:
pair - coordinate pair of the Square
Returns:
whether setting was done

setParent

void setParent(Pair current,
               Pair parent)
Set coordinates of the parent of a Square

Parameters:
current - coordinates pair of the Square
parent - coordinates of the parent of the Square

setParent

void setParent(int row,
               int col,
               Pair parent)
Set coordinates of the parent of a Square

Parameters:
row - row of the square
col - column of the square
parent - coordinates of the parent of the Square

clear

boolean clear(Pair pair)
Set the contents of a Square to blank


contains

boolean contains(int row,
                 int col,
                 int v)
Determine whether a Square contains specified contents.

Parameters:
row - the row of the square
col - the column of the square
Returns:
indication of whether the square contains the specified contents.

isMarked

boolean isMarked(int row,
                 int col)
Determine whether a Square has been visited during a search

Parameters:
row - the row of the square
col - the column of the square
Returns:
indication of whether the square has been visited

isBlocked

boolean isBlocked(int row,
                  int col)
Determine whether a Square has a blockage

Parameters:
row - the row of the square
col - the column of the square
Returns:
indication of whether the square is blocked

initialize

void initialize()
Construct the Squares of the Grid and initialize them.


clearParents

void clearParents()
Clear all parents in preparation for a search.


toString

public java.lang.String toString()
Return a String representation of this Grid.

Overrides:
toString in class java.lang.Object

getSquare

Square getSquare(Pair pair)
Get the Square located at a particular Pair of coordinates.


getParent

Pair getParent(Pair pair)
Get the parent of a Square located at a particular Pair of coordinates.