Merge branch 'Release_2_8_2_Branch' into
[jalview.git] / src / jalview / datamodel / Alignment.java
index 5e75725..bfe6406 100755 (executable)
@@ -22,7 +22,12 @@ package jalview.datamodel;
 
 import jalview.util.MessageManager;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
 
 /**
  * Data structure to hold and manipulate a multiple sequence alignment
@@ -1523,4 +1528,32 @@ public class Alignment implements AlignmentI
   {
     return dataset;
   }
+
+  /**
+   * Returns an iterable collection of annotations on this alignment which match
+   * the given criteria.
+   */
+  @Override
+  public Iterable<AlignmentAnnotation> findAnnotation(SequenceI datasequence,
+          String calcId, String label)
+  {
+    List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
+    for (AlignmentAnnotation ann : annotations)
+    {
+      // only sequence-linked annotations can qualify (have a datasequence)
+      if (ann.sequenceRef == null)
+      {
+        continue;
+      }
+      boolean matchDatasequence = (ann.sequenceRef.getDatasetSequence() == datasequence);
+      final String annCalcId = ann.getCalcId();
+      boolean matchCalcId = (annCalcId != null && annCalcId.equals(calcId));
+      boolean matchLabel = (ann.label != null && ann.label.equals(label));
+      if (matchDatasequence && matchCalcId && matchLabel)
+      {
+        result.add(ann);
+      }
+    }
+    return result;
+  }
 }