1 package jalview.datamodel;
4 * An immutable object representing one or more residue and corresponding
5 * alignment column positions for a sequence
7 public class SequenceCursor
10 * the aligned sequence this cursor applies to
12 public final SequenceI sequence;
15 * residue position in sequence (start...), 0 if undefined
17 public final int residuePosition;
20 * column position (1...) corresponding to residuePosition, or 0 if undefined
22 public final int columnPosition;
25 * column position (1...) of first residue in the sequence, or 0 if undefined
27 public final int firstColumnPosition;
30 * column position (1...) of last residue in the sequence, or 0 if undefined
32 public final int lastColumnPosition;
35 * a token which may be used to check whether this cursor is still valid for
36 * its sequence (allowing it to be ignored if the sequence has changed)
38 public final int token;
44 * sequence this cursor applies to
46 * residue position in sequence (start..)
48 * column position in alignment (1..)
50 * a token that may be validated by the sequence to check the cursor
53 public SequenceCursor(SequenceI seq, int resPos, int column, int tok)
55 this(seq, resPos, column, 0, 0, tok);
62 * sequence this cursor applies to
64 * residue position in sequence (start..)
66 * column position in alignment (1..)
68 * column position of the first residue in the sequence (1..), or 0
71 * column position of the last residue in the sequence (1..), or 0 if
74 * a token that may be validated by the sequence to check the cursor
77 public SequenceCursor(SequenceI seq, int resPos, int column, int firstResCol,
78 int lastResCol, int tok)
81 residuePosition = resPos;
82 columnPosition = column;
83 firstColumnPosition = firstResCol;
84 lastColumnPosition = lastResCol;
91 int hash = 31 * residuePosition;
92 hash = 31 * hash + columnPosition;
93 hash = 31 * hash + token;
96 hash += sequence.hashCode();
102 * Two cursors are equal if they refer to the same sequence object and have
103 * the same residue position, column position and token value
106 public boolean equals(Object obj)
108 if (!(obj instanceof SequenceCursor))
112 SequenceCursor sc = (SequenceCursor) obj;
113 return sequence == sc.sequence && residuePosition == sc.residuePosition
114 && columnPosition == sc.columnPosition && token == sc.token;
118 public String toString()
120 String name = sequence == null ? "" : sequence.getName();
121 return String.format("%s:Pos%d:Col%d:startCol%d:endCol%d:tok%d", name,
122 residuePosition, columnPosition, firstColumnPosition,
123 lastColumnPosition, token);