2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
24 * An immutable object representing one or more residue and corresponding
25 * alignment column positions for a sequence
27 public class SequenceCursor
30 * the aligned sequence this cursor applies to
32 public final SequenceI sequence;
35 * residue position in sequence (start...), 0 if undefined
37 public final int residuePosition;
40 * column position (1...) corresponding to residuePosition, or 0 if undefined
42 public final int columnPosition;
45 * column position (1...) of first residue in the sequence, or 0 if undefined
47 public final int firstColumnPosition;
50 * column position (1...) of last residue in the sequence, or 0 if undefined
52 public final int lastColumnPosition;
55 * a token which may be used to check whether this cursor is still valid for
56 * its sequence (allowing it to be ignored if the sequence has changed)
58 public final int token;
64 * sequence this cursor applies to
66 * residue position in sequence (start..)
68 * column position in alignment (1..)
70 * a token that may be validated by the sequence to check the cursor
73 public SequenceCursor(SequenceI seq, int resPos, int column, int tok)
75 this(seq, resPos, column, 0, 0, tok);
82 * sequence this cursor applies to
84 * residue position in sequence (start..)
86 * column position in alignment (1..)
88 * column position of the first residue in the sequence (1..), or 0
91 * column position of the last residue in the sequence (1..), or 0 if
94 * a token that may be validated by the sequence to check the cursor
97 public SequenceCursor(SequenceI seq, int resPos, int column,
98 int firstResCol, int lastResCol, int tok)
101 residuePosition = resPos;
102 columnPosition = column;
103 firstColumnPosition = firstResCol;
104 lastColumnPosition = lastResCol;
109 public int hashCode()
111 int hash = 31 * residuePosition;
112 hash = 31 * hash + columnPosition;
113 hash = 31 * hash + token;
114 if (sequence != null)
116 hash += sequence.hashCode();
122 * Two cursors are equal if they refer to the same sequence object and have
123 * the same residue position, column position and token value
126 public boolean equals(Object obj)
128 if (!(obj instanceof SequenceCursor))
132 SequenceCursor sc = (SequenceCursor) obj;
133 return sequence == sc.sequence && residuePosition == sc.residuePosition
134 && columnPosition == sc.columnPosition && token == sc.token;
138 public String toString()
140 String name = sequence == null ? "" : sequence.getName();
141 return String.format("%s:Pos%d:Col%d:startCol%d:endCol%d:tok%d", name,
142 residuePosition, columnPosition, firstColumnPosition,
143 lastColumnPosition, token);