- public boolean equals(Object rhs) {
- if (!(rhs instanceof CellAttributes)) {
- return false;
- }
-
- CellAttributes that = (CellAttributes)rhs;
- return ((bold == that.bold) &&
- (blink == that.blink) &&
- (reverse == that.reverse) &&
- (underline == that.underline) &&
- (protect == that.protect) &&
- (foreColor == that.foreColor) &&
- (backColor == that.backColor));
- }
-
- /**
- * Set my field values to that's field
- */
- public void setTo(Object rhs) {
- CellAttributes that = (CellAttributes)rhs;
-
- this.bold = that.bold;
- this.blink = that.blink;
- this.reverse = that.reverse;
- this.underline = that.underline;
- this.protect = that.protect;
- this.foreColor = that.foreColor;
- this.backColor = that.backColor;
- }
-
- /**
- * Convert enum to string
- *
- * @param color Color.RED, Color.BLUE, etc.
- * @return "red", "blue", etc.
- */
- static public String stringFromColor(Color color) {
- if (color.equals(Color.BLACK)) {
- return "black";
- } else if (color.equals(Color.WHITE)) {
- return "white";
- } else if (color.equals(Color.RED)) {
- return "red";
- } else if (color.equals(Color.CYAN)) {
- return "cyan";
- } else if (color.equals(Color.GREEN)) {
- return "green";
- } else if (color.equals(Color.MAGENTA)) {
- return "magenta";
- } else if (color.equals(Color.BLUE)) {
- return "blue";
- } else if (color.equals(Color.YELLOW)) {
- return "yellow";
- }
- throw new IllegalArgumentException("Invalid Color value: " +
- color.value);
- }
-
- /**
- * Convert string to enum
- *
- * @param color "red", "blue", etc.
- * @return Color.RED, Color.BLUE, etc.
- */
- static private Color colorFromString(String color) {
- switch (color.toLowerCase()) {
- case "black":
- return Color.BLACK;
- case "white":
- return Color.WHITE;
- case "red":
- return Color.RED;
- case "cyan":
- return Color.CYAN;
- case "green":
- return Color.GREEN;
- case "magenta":
- return Color.MAGENTA;
- case "blue":
- return Color.BLUE;
- case "yellow":
- return Color.YELLOW;
- case "brown":
- return Color.YELLOW;
- default:
- // Let unknown strings become white
- return Color.WHITE;
- }
- }
-
- /**
- * Make human-readable description of this CellAttributes
+ public boolean equals(final Object rhs) {
+ if (!(rhs instanceof CellAttributes)) {
+ return false;
+ }
+
+ CellAttributes that = (CellAttributes) rhs;
+ return ((bold == that.bold)
+ && (blink == that.blink)
+ && (reverse == that.reverse)
+ && (underline == that.underline)
+ && (protect == that.protect)
+ && (foreColor == that.foreColor)
+ && (backColor == that.backColor));
+ }
+
+ /**
+ * 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) + (bold ? 1 : 0);
+ hash = (B * hash) + (blink ? 1 : 0);
+ hash = (B * hash) + (underline ? 1 : 0);
+ hash = (B * hash) + (reverse ? 1 : 0);
+ hash = (B * hash) + (protect ? 1 : 0);
+ hash = (B * hash) + foreColor.hashCode();
+ hash = (B * hash) + backColor.hashCode();
+ return hash;
+ }
+
+ /**
+ * Set my field values to that's field.
+ *
+ * @param rhs another CellAttributes instance
+ */
+ public void setTo(final Object rhs) {
+ CellAttributes that = (CellAttributes) rhs;
+
+ this.bold = that.bold;
+ this.blink = that.blink;
+ this.reverse = that.reverse;
+ this.underline = that.underline;
+ this.protect = that.protect;
+ this.foreColor = that.foreColor;
+ this.backColor = that.backColor;
+ }
+
+ /**
+ * Make human-readable description of this CellAttributes.
+ *
+ * @return displayable String