JAL-4124 MappableContactMatrix equivalence and hashCode ensuring non-redundant set...
[jalview.git] / src / jalview / ws / datamodel / alphafold / MappableContactMatrix.java
index cc96ac4..5f27a2c 100644 (file)
@@ -487,4 +487,25 @@ public abstract class MappableContactMatrix<T extends MappableContactMatrix<T>>
     return mappedMatrix.getElementAt(_column, i);
   }
 
+  @Override
+  public int hashCode()
+  {
+    return 7 * (refSeq != null ? refSeq.hashCode() : 0)
+            + 11 * (toSeq != null ? toSeq.hashCode() : 0)
+            + 13 * (mappedMatrix != null ? mappedMatrix.hashCode() : 0)
+            + length * 3;
+  }
+
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (obj == null || !(obj.getClass().equals(getClass())))
+    {
+      return false;
+    }
+    T them = (T) obj;
+    return mappedMatrix == them.mappedMatrix && length == them.length
+            && refSeq == them.refSeq && toSeq.equals(them.toSeq);
+
+  }
 }