JAL-2154 refactor setSequenceAt to replaceSequenceAt, fixed implementation and docs
authorJim Procter <jprocter@issues.jalview.org>
Fri, 19 Aug 2016 10:10:04 +0000 (11:10 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 19 Aug 2016 10:10:04 +0000 (11:10 +0100)
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java

index dcfbaad..fd918fc 100755 (executable)
@@ -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;
     }
   }
 
index f1db4c0..1d37fa6 100755 (executable)
@@ -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