X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequenceCursor.java;h=24752bf4b1c2a9e94947bc2537e2f3e0b2cc81b0;hb=0dc22d603ad9d58a4ed951fc2146f7a027917a2c;hp=482e0fade17fffb412e0b35cdb0033b1f93218ed;hpb=0e65ec37e2c956e0ad94feda6fd07b7c3a9003ee;p=jalview.git diff --git a/src/jalview/datamodel/SequenceCursor.java b/src/jalview/datamodel/SequenceCursor.java index 482e0fa..24752bf 100644 --- a/src/jalview/datamodel/SequenceCursor.java +++ b/src/jalview/datamodel/SequenceCursor.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.datamodel; /** @@ -22,16 +42,104 @@ public class SequenceCursor public final int columnPosition; /** + * column position (1...) of first residue in the sequence, or 0 if undefined + */ + public final int firstColumnPosition; + + /** + * column position (1...) of last residue in the sequence, or 0 if undefined + */ + public final int lastColumnPosition; + + /** * a token which may be used to check whether this cursor is still valid for * its sequence (allowing it to be ignored if the sequence has changed) */ 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) { + this(seq, resPos, column, 0, 0, tok); + } + + /** + * Constructor + * + * @param seq + * sequence this cursor applies to + * @param resPos + * residue position in sequence (start..) + * @param column + * column position in alignment (1..) + * @param firstResCol + * column position of the first residue in the sequence (1..), or 0 + * if not known + * @param lastResCol + * column position of the last residue in the sequence (1..), or 0 if + * not known + * @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 firstResCol, + int lastResCol, int tok) + { sequence = seq; residuePosition = resPos; columnPosition = column; + firstColumnPosition = firstResCol; + lastColumnPosition = lastResCol; 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() + { + String name = sequence == null ? "" : sequence.getName(); + return String.format("%s:Pos%d:Col%d:startCol%d:endCol%d:tok%d", name, + residuePosition, columnPosition, firstColumnPosition, + lastColumnPosition, token); + } }