From: Jim Procter Date: Fri, 19 Aug 2016 10:10:04 +0000 (+0100) Subject: JAL-2154 refactor setSequenceAt to replaceSequenceAt, fixed implementation and docs X-Git-Tag: Release_2_10_0~47^2~4^2~43^2~38 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4956fb78f7222e84d0d7008a6b91146d6c61d151;p=jalview.git JAL-2154 refactor setSequenceAt to replaceSequenceAt, fixed implementation and docs --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index dcfbaad..fd918fc 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -256,18 +256,22 @@ public class Alignment implements AlignmentI } } - /** - * Adds a sequence to the alignment. Recalculates maxLength and size. - * - * @param snew - */ @Override - public void setSequenceAt(int i, SequenceI snew) + public SequenceI replaceSequenceAt(int i, SequenceI snew) { synchronized (sequences) { - deleteSequence(i); - sequences.set(i, snew); + if (sequences.size() > i) + { + return sequences.set(i, snew); + + } + else + { + sequences.add(snew); + hiddenSequences.adjustHeightSequenceAdded(); + } + return null; } } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index f1db4c0..1d37fa6 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -108,11 +108,14 @@ public interface AlignmentI extends AnnotatedCollectionI * Used to set a particular index of the alignment with the given sequence. * * @param i - * Index of sequence to be updated. + * Index of sequence to be updated. if i>length, sequence will be + * added to end, with no intervening positions. * @param seq - * New sequence to be inserted. + * New sequence to be inserted. The existing sequence at position i + * will be replaced. + * @return existing sequence (or null if i>current length) */ - void setSequenceAt(int i, SequenceI seq); + SequenceI replaceSequenceAt(int i, SequenceI seq); /** * Deletes a sequence from the alignment