/**
* This class represents a single text cell on the screen.
*/
-public class Cell extends CellAttributes {
+public final class Cell extends CellAttributes {
/**
* The character at this cell.
*
* @return cell character
*/
- public final char getChar() {
+ public char getChar() {
return ch;
}
*
* @param ch new cell character
*/
- public final void setChar(final char ch) {
+ public void setChar(final char ch) {
this.ch = ch;
}
* Reset this cell to a blank.
*/
@Override
- public final void reset() {
+ public void reset() {
super.reset();
ch = ' ';
}
*
* @return true if this cell has default attributes.
*/
- public final boolean isBlank() {
+ public boolean isBlank() {
if ((getForeColor().equals(Color.WHITE))
&& (getBackColor().equals(Color.BLACK))
&& !getBold()
* @return true if all fields are equal
*/
@Override
- public final boolean equals(final Object rhs) {
+ public boolean equals(final Object rhs) {
if (!(rhs instanceof Cell)) {
return false;
}
&& (ch == that.ch));
}
+ /**
+ * Hashcode uses all fields in equals().
+ *
+ * @return the hash
+ */
+ @Override
+ public int hashCode() {
+ int A = 13;
+ int B = 23;
+ int hash = A;
+ hash = (B * hash) + super.hashCode();
+ hash = (B * hash) + (int)ch;
+ return hash;
+ }
+
/**
* Set my field values to that's field.
*
* @param rhs an instance of either Cell or CellAttributes
*/
@Override
- public final void setTo(final Object rhs) {
+ public void setTo(final Object rhs) {
// Let this throw a ClassCastException
CellAttributes thatAttr = (CellAttributes) rhs;
super.setTo(thatAttr);
*
* @param that a CellAttributes instance
*/
- public final void setAttr(final CellAttributes that) {
+ public void setAttr(final CellAttributes that) {
super.setTo(that);
}
* @return displayable String
*/
@Override
- public final String toString() {
+ public String toString() {
return String.format("fore: %d back: %d bold: %s blink: %s ch %c",
getForeColor(), getBackColor(), getBold(), getBlink(), ch);
}