com.holub.life
Interface Cell

All Known Implementing Classes:
Neighborhood, Resident

public interface Cell

This interface is the basic unit that comprises a life board. It's implemented both by Resident (which represents an individual cell on the board) and Neighborhood, which represents a group of cells.


Nested Class Summary
static interface Cell.Memento
          The Cell.Memento interface stores the state of a Cell and all its subcells for future restoration.
 
Field Summary
static Cell DUMMY
          The DUMMY Singleton represents a permanently dead (thus stable) cell.
static boolean LOAD
          Possible value for the "load" argument to transfer()
static boolean STORE
          Possible value for the "load" argument to transfer()
 
Method Summary
 void clear()
          Set the cell and all subcells into a "dead" state.
 Cell create()
          Return a fresh (newly created) object identical to yourself in content.
 Storable createMemento()
          This method is used by container of the outermost cell.
 Cell edge(int row, int column)
          Access a specific contained cell located at the edge of the composite cell.
 boolean figureNextState(Cell north, Cell south, Cell east, Cell west, Cell northeast, Cell northwest, Cell southeast, Cell southwest)
          Figure out the next state of the cell, given the specified neighbors.
 boolean isAlive()
          Return true if this cell or any subcells are alive.
 Direction isDisruptiveTo()
          Returns a Direction indicated the directions of the cells that have changed state.
 void redraw(Graphics g, Rectangle here, boolean drawAll)
          Redraw yourself in the indicated rectangle on the indicated Graphics object if ncessary.
 boolean transfer(Storable memento, Point upperLeftCorner, boolean doLoad)
          This method is used internally to save or restore the state of a cell from a memento.
 boolean transition()
          Transition to the state computed by the most recent call to figureNextState(com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell)
 void userClicked(Point here, Rectangle surface)
          A user has clicked somewhere within you.
 int widthInCells()
          Return the specified width plus the current cell's width
 

Field Detail

STORE

static final boolean STORE
Possible value for the "load" argument to transfer()

See Also:
Constant Field Values

LOAD

static final boolean LOAD
Possible value for the "load" argument to transfer()

See Also:
Constant Field Values

DUMMY

static final Cell DUMMY
The DUMMY Singleton represents a permanently dead (thus stable) cell. It's used for the edges of the grid. It's a singleton. The Dummy class is private, but it is accessed through the public DUMMY field, declared below. I'd like this class to be private, but the JLS doesn't allow private members in an interface.

Method Detail

figureNextState

boolean figureNextState(Cell north,
                        Cell south,
                        Cell east,
                        Cell west,
                        Cell northeast,
                        Cell northwest,
                        Cell southeast,
                        Cell southwest)
Figure out the next state of the cell, given the specified neighbors.

Returns:
true if the cell is unstable (changed state).

edge

Cell edge(int row,
          int column)
Access a specific contained cell located at the edge of the composite cell.

Parameters:
row - The requested row. Must be on the edge of the block.
column - The requested column. Must be on the edge of the block.
Returns:
true if the the state changed.

transition

boolean transition()
Transition to the state computed by the most recent call to figureNextState(com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell)

Returns:
true if a changed of state happened during the transition.

redraw

void redraw(Graphics g,
            Rectangle here,
            boolean drawAll)
Redraw yourself in the indicated rectangle on the indicated Graphics object if ncessary. This method is meant for a conditional redraw, where some of the cells might not be refreshed (if they haven't changed state, for example).

Parameters:
g - redraw using this graphics,
here - a rectangle that describes the bounds of the current cell.
drawAll - if true, draw an entire compound cell; otherwise, draw only the subcells that need to be redrawn.

userClicked

void userClicked(Point here,
                 Rectangle surface)
A user has clicked somewhere within you.

Parameters:
here - The position of the click relative to the bounding rectangle of the current Cell.

isAlive

boolean isAlive()
Return true if this cell or any subcells are alive.


widthInCells

int widthInCells()
Return the specified width plus the current cell's width


create

Cell create()
Return a fresh (newly created) object identical to yourself in content.


isDisruptiveTo

Direction isDisruptiveTo()
Returns a Direction indicated the directions of the cells that have changed state.

Returns:
A Direction object that indicates the edge or edges on which a change has occured.

clear

void clear()
Set the cell and all subcells into a "dead" state.


transfer

boolean transfer(Storable memento,
                 Point upperLeftCorner,
                 boolean doLoad)
This method is used internally to save or restore the state of a cell from a memento.

Returns:
true if this cell was modified by the transfer.

createMemento

Storable createMemento()
This method is used by container of the outermost cell. It is not used internally. It need be implemented only by whatever class defines the outermost cell in the universe. Other cell implementions should throw an UnsupportedOperationException when this method is called.