JAL-1686 ViewStyle.hashCode implemented
[jalview.git] / src / jalview / viewmodel / styles / ViewStyle.java
index d6e529c..3ed5634 100644 (file)
@@ -270,11 +270,44 @@ public class ViewStyle implements ViewStyleI
     // return equivalent(this, (ViewStyle) other);
   }
 
+  /**
+   * Overridden to ensure that whenever vs1.equals(vs2) then vs1.hashCode() ==
+   * vs2.hashCode()
+   */
   @Override
   public int hashCode()
   {
-    return 0; // TODO
+    /*
+     * No need to include all properties, just a selection...
+     */
+    int hash = 0;
+    int m = 1;
+    // Boolean.hashCode returns 1231 or 1237
+    hash += m++ * Boolean.valueOf(this.abovePIDThreshold).hashCode();
+    hash += m++ * Boolean.valueOf(this.centreColumnLabels).hashCode();
+    hash += m++ * Boolean.valueOf(this.colourAppliesToAllGroups).hashCode();
+    hash += m++ * Boolean.valueOf(this.displayReferenceSeq).hashCode();
+    hash += m++ * Boolean.valueOf(this.renderGaps).hashCode();
+    hash += m++ * Boolean.valueOf(this.rightAlignIds).hashCode();
+    hash += m++ * Boolean.valueOf(this.scaleProteinAsCdna).hashCode();
+    hash += m++ * Boolean.valueOf(this.scaleRightWrapped).hashCode();
+    hash += m++ * Boolean.valueOf(this.seqNameItalics).hashCode();
+    hash += m++ * Boolean.valueOf(this.showAnnotation).hashCode();
+    hash += m++ * Boolean.valueOf(this.showBoxes).hashCode();
+    hash += m++ * Boolean.valueOf(this.showdbrefs).hashCode();
+    hash += m++ * Boolean.valueOf(this.showJVSuffix).hashCode();
+    hash += m++ * Boolean.valueOf(this.showSequenceFeatures).hashCode();
+    hash += m++ * Boolean.valueOf(this.showUnconserved).hashCode();
+    hash += m++ * Boolean.valueOf(this.wrapAlignment).hashCode();
+    hash += m++ * this.charHeight;
+    hash += m++ * this.charWidth;
+    hash += m++ * fontSize;
+    hash += m++ * fontStyle;
+    hash += m++ * idWidth;
+    hash += String.valueOf(this.fontName).hashCode();
+    return hash;
   }
+
   /**
    * @return the upperCasebold
    */