X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FCell.java;h=511963c28ac23c0f458addcafc56090bb7697bb8;hb=e826b451baf0d1e66d09ce03a6fefee2eb8386f5;hp=f110d3362e6c61b3fe67ff94802d66afc57043c5;hpb=7b5261bc5b641e0769902f014e3b21f61050b02b;p=fanfix.git diff --git a/src/jexer/bits/Cell.java b/src/jexer/bits/Cell.java index f110d33..511963c 100644 --- a/src/jexer/bits/Cell.java +++ b/src/jexer/bits/Cell.java @@ -33,7 +33,7 @@ package jexer.bits; /** * 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. @@ -45,7 +45,7 @@ public class Cell extends CellAttributes { * * @return cell character */ - public final char getChar() { + public char getChar() { return ch; } @@ -54,7 +54,7 @@ public class Cell extends CellAttributes { * * @param ch new cell character */ - public final void setChar(final char ch) { + public void setChar(final char ch) { this.ch = ch; } @@ -62,7 +62,7 @@ public class Cell extends CellAttributes { * Reset this cell to a blank. */ @Override - public final void reset() { + public void reset() { super.reset(); ch = ' '; } @@ -74,7 +74,7 @@ public class Cell extends CellAttributes { * * @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() @@ -97,7 +97,7 @@ public class Cell extends CellAttributes { * @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; } @@ -107,13 +107,28 @@ public class Cell extends CellAttributes { && (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); @@ -129,7 +144,7 @@ public class Cell extends CellAttributes { * * @param that a CellAttributes instance */ - public final void setAttr(final CellAttributes that) { + public void setAttr(final CellAttributes that) { super.setTo(that); } @@ -161,7 +176,7 @@ public class Cell extends CellAttributes { * @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); }