Class BoardCell

java.lang.Object
  extended by BoardCell
All Implemented Interfaces:
java.lang.Comparable<BoardCell>

public class BoardCell
extends java.lang.Object
implements java.lang.Comparable<BoardCell>

Encapsulate a (row,column) entry so that the entry can be hashed, compared, and stored as a single entry. This implementation provides simple methods for determining when one BoardCell is a neighbor of another. Here neighbor means adjacent horizontally, vertically, or diagonally.


Field Summary
 int col
           
 int row
           
 
Constructor Summary
BoardCell(int r, int c)
           
 
Method Summary
 int compareTo(BoardCell cell)
          Returns value indicating whether cell is less than, equal to, or greater than this cell as determined first by row value, then by column value for cells whose rows are equal
 boolean equals(java.lang.Object o)
           
 int hashCode()
           
 boolean isNeighbor(BoardCell c)
          Returns true iff c is a neighbor of this board cell; neighbor means adjacent horizontally, vertically, or diagonally (not self).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

row

public int row

col

public int col
Constructor Detail

BoardCell

public BoardCell(int r,
                 int c)
Method Detail

isNeighbor

public boolean isNeighbor(BoardCell c)
Returns true iff c is a neighbor of this board cell; neighbor means adjacent horizontally, vertically, or diagonally (not self).

Parameters:
c - is BoardCell compared to this one for adjacency
Returns:
true iff c adjacent to this BoardCell

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(BoardCell cell)
Returns value indicating whether cell is less than, equal to, or greater than this cell as determined first by row value, then by column value for cells whose rows are equal

Specified by:
compareTo in interface java.lang.Comparable<BoardCell>
Parameters:
cell - compared to this BoardCell
Returns:
row difference if rows aren't the same, column difference if rows are the same