JAL-2526 additional tests for findPosition with/without cursor/edit
[jalview.git] / src / jalview / datamodel / SequenceCursor.java
index 482e0fa..f439ee1 100644 (file)
@@ -27,6 +27,19 @@ public class SequenceCursor
    */
   public final int token;
 
+  /**
+   * Constructor
+   * 
+   * @param seq
+   *          sequence this cursor applies to
+   * @param resPos
+   *          residue position in sequence (start..)
+   * @param column
+   *          column position in alignment (1..)
+   * @param tok
+   *          a token that may be validated by the sequence to check the cursor
+   *          is not stale
+   */
   public SequenceCursor(SequenceI seq, int resPos, int column, int tok)
   {
     sequence = seq;
@@ -34,4 +47,40 @@ public class SequenceCursor
     columnPosition = column;
     token = tok;
   }
+
+  @Override
+  public int hashCode()
+  {
+    int hash = 31 * residuePosition;
+    hash = 31 * hash + columnPosition;
+    hash = 31 * hash + token;
+    if (sequence != null)
+    {
+      hash += sequence.hashCode();
+    }
+    return hash;
+  }
+
+  /**
+   * Two cursors are equal if they refer to the same sequence object and have
+   * the same residue position, column position and token value
+   */
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (!(obj instanceof SequenceCursor))
+    {
+      return false;
+    }
+    SequenceCursor sc = (SequenceCursor) obj;
+    return sequence == sc.sequence && residuePosition == sc.residuePosition
+            && columnPosition == sc.columnPosition && token == sc.token;
+  }
+
+  @Override
+  public String toString()
+  {
+    return (sequence == null ? "" : sequence.getName()) + ":Pos"
+            + residuePosition + ":Col" + columnPosition + ":tok" + token;
+  }
 }