public class CellState
{
    // OVERVIEW: A CellState is an immutable object that represents
    //           the state of a cell, either alive or dead.
    //

    private boolean alive;
    
    private CellState (boolean isalive)
       // EFFECTS: Initializes this to alive if isalive is true,
       //    otherwise initializes this to the dead state.
    {
        this.alive = isalive;
    }

    static public /*@non_null@*/ CellState createAlive()
       // EFFECTS: Returns an alive cell state. 
    {
        return new CellState (true);
    }
    
    static public /*@non_null@*/ CellState createDead ()
       // EFFECTS: Returns a dead cell state. 
    {
        return new CellState(false);
    }

    public boolean equals (CellState s) {
        return s.alive == alive;
    }

    public boolean equals (Object o) {
        try { 
            return equals ((CellState) o); 
        } catch (ClassCastException e) { 
            return false;
        }
    }

    public boolean isAlive ()
       // EFFECTS: Returns true iff this is alive.
    {
        return alive;
    }
}

