JAL-1610 check reference annotations against alignment, not sequence
[jalview.git] / src / jalview / datamodel / Sequence.java
index 69d6da2..0652fb5 100755 (executable)
@@ -879,22 +879,30 @@ public class Sequence implements SequenceI
     return datasetSequence;
   }
 
+  /**
+   * Returns a new array containing this sequence's annotations, or null.
+   */
   public AlignmentAnnotation[] getAnnotation()
   {
-    if (annotation == null)
-    {
-      return null;
-    }
-
-    AlignmentAnnotation[] ret = new AlignmentAnnotation[annotation.size()];
-    for (int r = 0; r < ret.length; r++)
-    {
-      ret[r] = annotation.elementAt(r);
-    }
+    return annotation == null ? null : annotation
+            .toArray(new AlignmentAnnotation[annotation.size()]);
+  }
 
-    return ret;
+  /**
+   * Returns true if this sequence has the given annotation (by object
+   * identity).
+   */
+  @Override
+  public boolean hasAnnotation(AlignmentAnnotation ann)
+  {
+    return annotation == null ? false : annotation.contains(ann);
   }
 
+  /**
+   * Add the given annotation, if not already added, and set its sequence ref to
+   * be this sequence. Does nothing if this sequence's annotations already
+   * include this annotation (by identical object reference).
+   */
   public void addAlignmentAnnotation(AlignmentAnnotation annotation)
   {
     if (this.annotation == null)