Merge branch 'develop' into Release_2_9_Branch
[jalview.git] / src / jalview / viewmodel / styles / ViewStyle.java
index d6e529c..a0ba633 100644 (file)
@@ -1,9 +1,29 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.viewmodel.styles;
 
-import java.awt.Color;
-
 import jalview.api.ViewStyleI;
 
+import java.awt.Color;
+
 /**
  * A container for holding alignment view properties. View properties are
  * data-independent, which means they can be safely copied between views
@@ -255,7 +275,8 @@ public class ViewStyle implements ViewStyleI
             && getWrapAlignment() == vs.getWrapAlignment() && getWrappedWidth() == vs
             .getWrappedWidth());
     /*
-     * and compare non-primitive types; syntax below will match null with null values
+     * and compare non-primitive types; syntax below will match null with null
+     * values
      */
     match = match
             && String.valueOf(getFontName()).equals(
@@ -270,11 +291,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
    */
@@ -609,7 +663,6 @@ public class ViewStyle implements ViewStyleI
     abovePIDThreshold = b;
   }
 
-  
   /**
    * DOCUMENT ME!
    * 
@@ -634,7 +687,6 @@ public class ViewStyle implements ViewStyleI
     this.charWidth = w;
   }
 
-
   /**
    * @param value
    *          indicating if subsequent colourscheme changes will be propagated