removeAlignmentAnnotation only removes annotation objects referenced by the alignment...
authorjprocter <Jim Procter>
Tue, 1 May 2007 11:46:38 +0000 (11:46 +0000)
committerjprocter <Jim Procter>
Tue, 1 May 2007 11:46:38 +0000 (11:46 +0000)
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java

index abaa80f..536ccab 100755 (executable)
@@ -460,17 +460,11 @@ public class Alignment
 
     return true;
   }
-
-  /**
-   * DOCUMENT ME!
-   *
-   * @param aa DOCUMENT ME!
+  /* (non-Javadoc)
+   * @see jalview.datamodel.AlignmentI#deleteAnnotation(jalview.datamodel.AlignmentAnnotation)
    */
   public void deleteAnnotation(AlignmentAnnotation aa)
   {
-    if(aa.sequenceRef!=null)
-      aa.sequenceRef.removeAlignmentAnnotation(aa);
-
     int aSize = 1;
 
     if (annotations != null)
@@ -485,12 +479,14 @@ public class Alignment
 
     AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1];
 
+    boolean swap=false;
     int tIndex = 0;
 
-    for (int i = 0; i < aSize; i++)
+    for (int i = 0; tIndex<temp.length && i < aSize; i++)
     {
       if (annotations[i] == aa)
       {
+        swap=true;
         continue;
       }
 
@@ -498,7 +494,12 @@ public class Alignment
       tIndex++;
     }
 
-    annotations = temp;
+    if (swap)
+    {
+      annotations = temp;
+      if(aa.sequenceRef!=null)
+        aa.sequenceRef.removeAlignmentAnnotation(aa);
+    }
   }
 
   /**
index 9141a51..2b210cc 100755 (executable)
@@ -178,8 +178,11 @@ public interface AlignmentI
   public void setAnnotationIndex(AlignmentAnnotation aa, int index);
 
   /**
-   * Deletes a specific AlignmentAnnotation from the alignment.
-   *
+   * Deletes a specific AlignmentAnnotation from the alignment,
+   * and removes its reference from any SequenceI object's annotation
+   * if and only if aa is contained within the alignment's annotation
+   * vector.
+   * 
    * @param aa the annotation to delete
    */
   public void deleteAnnotation(AlignmentAnnotation aa);