JAL-4136 Replace uses of isBlank with isEmpty
[jalview.git] / src / jalview / datamodel / Sequence.java
index 009a290..4230366 100755 (executable)
@@ -86,7 +86,6 @@ public class Sequence extends ASequence implements SequenceI
   HiddenMarkovModel hmm;
 
   boolean isHMMConsensusSequence = false;
-
   private DBModList<DBRefEntry> dbrefs; // controlled access
 
   /**
@@ -259,6 +258,21 @@ public class Sequence extends ASequence implements SequenceI
   }
 
   /**
+   * Create a new sequence object from a characters array using default values
+   * of 1 and -1 for start and end. The array used to create the sequence is
+   * copied and is not stored internally.
+   * 
+   * @param name
+   *          sequence name
+   * @param sequence
+   *          list of residues
+   */
+  public Sequence(String name, char[] sequence)
+  {
+    this(name, Arrays.copyOf(sequence, sequence.length), 1, -1);
+  }
+
+  /**
    * Creates a new Sequence object with new AlignmentAnnotations but inherits
    * any existing dataset sequence reference. If non exists, everything is
    * copied.
@@ -370,7 +384,6 @@ public class Sequence extends ASequence implements SequenceI
     {
       this.hmm = new HiddenMarkovModel(seq.getHMM(), this);
     }
-
   }
 
   @Override
@@ -1426,6 +1439,7 @@ public class Sequence extends ASequence implements SequenceI
   @Override
   public void addDBRef(DBRefEntry entry)
   {
+    // TODO JAL-3980 maintain as sorted list
     if (datasetSequence != null)
     {
       datasetSequence.addDBRef(entry);
@@ -1436,6 +1450,7 @@ public class Sequence extends ASequence implements SequenceI
     {
       dbrefs = new DBModList<>();
     }
+    // TODO JAL-3979 LOOK UP RATHER THAN SWEEP FOR EFFICIENCY
 
     for (int ib = 0, nb = dbrefs.size(); ib < nb; ib++)
     {
@@ -1810,14 +1825,30 @@ public class Sequence extends ASequence implements SequenceI
   public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
           String label)
   {
+    return getAlignmentAnnotations(calcId, label, null, true);
+  }
+
+  @Override
+  public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
+          String label, String description)
+  {
+    return getAlignmentAnnotations(calcId, label, description, false);
+  }
+
+  private List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
+          String label, String description, boolean ignoreDescription)
+  {
     List<AlignmentAnnotation> result = new ArrayList<>();
     if (this.annotation != null)
     {
       for (AlignmentAnnotation ann : annotation)
       {
         String id = ann.getCalcId();
-        if (id != null && id.equals(calcId)
-                && ann.label != null && ann.label.equals(label))
+        if ((id != null && id.equals(calcId))
+                && (ann.label != null && ann.label.equals(label))
+                && ((ignoreDescription && description == null)
+                        || (ann.description != null
+                                && ann.description.equals(description))))
         {
           result.add(ann);
         }
@@ -1963,7 +1994,6 @@ public class Sequence extends ASequence implements SequenceI
     }
     return false;
   }
-
   /**
    * {@inheritDoc}
    */