From: gmungoc Date: Fri, 11 May 2018 11:19:52 +0000 (+0100) Subject: JAL-2986 corrected findIndex for out of range residue value X-Git-Tag: Release_2_11_0~38 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d716c9b072f989bef39c6eba038f779ce98396a8;p=jalview.git JAL-2986 corrected findIndex for out of range residue value --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 59c3fb1..33de452 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -445,7 +445,7 @@ public class Sequence extends ASequence implements SequenceI @Override public Vector getAllPDBEntries() { - return pdbIds == null ? new Vector() : pdbIds; + return pdbIds == null ? new Vector<>() : pdbIds; } /** @@ -815,7 +815,7 @@ public class Sequence extends ASequence implements SequenceI * @param curs * @return */ - protected int findIndex(int pos, SequenceCursor curs) + protected int findIndex(final int pos, SequenceCursor curs) { if (!isValidCursor(curs)) { @@ -841,10 +841,15 @@ public class Sequence extends ASequence implements SequenceI while (newPos != pos) { col += delta; // shift one column left or right - if (col < 0 || col == sequence.length) + if (col < 0) { break; } + if (col == sequence.length) + { + col--; // return last column if we failed to reach pos + break; + } if (!Comparison.isGap(sequence[col])) { newPos += delta; @@ -852,7 +857,14 @@ public class Sequence extends ASequence implements SequenceI } col++; // convert back to base 1 - updateCursor(pos, col, curs.firstColumnPosition); + + /* + * only update cursor if we found the target position + */ + if (newPos == pos) + { + updateCursor(pos, col, curs.firstColumnPosition); + } return col; }