JAL-845 SplitFrame for "show product" and after aligning from SplitFrame
[jalview.git] / src / jalview / datamodel / SearchResults.java
index 7a241fd..a53d103 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.datamodel;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -39,8 +40,14 @@ public class SearchResults
   {
     SequenceI sequence;
 
+    /*
+     * Start position of match in sequence (base 1)
+     */
     int start;
 
+    /*
+     * End position (inclusive) (base 1)
+     */
     int end;
 
     public Match(SequenceI seq, int start, int end)
@@ -64,6 +71,16 @@ public class SearchResults
     {
       return end;
     }
+
+    /**
+     * Returns the string of characters in the matched region.
+     */
+    @Override
+    public String toString()
+    {
+      char[] chars = sequence.getSequence();
+      return String.valueOf(Arrays.copyOfRange(chars, start - 1, end));
+    }
   }
 
   /**
@@ -228,4 +245,22 @@ public class SearchResults
   {
     return matches;
   }
+
+  /**
+   * Return the results as a string of characters. Meant for use when the
+   * context ensures that all matches are to regions of the same sequence
+   * (otherwise the result is meaningless).
+   * 
+   * @return
+   */
+  @Override
+  public String toString()
+  {
+    StringBuilder result = new StringBuilder(256);
+    for (Match m : matches)
+    {
+      result.append(m.toString());
+    }
+    return result.toString();
+  }
 }