Merge branch 'develop' into features/JAL-845splitPaneMergeDevelop
[jalview.git] / src / jalview / datamodel / SearchResults.java
index a53d103..e62e58a 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -40,16 +40,26 @@ public class SearchResults
   {
     SequenceI sequence;
 
-    /*
+    /**
      * Start position of match in sequence (base 1)
      */
     int start;
 
-    /*
+    /**
      * End position (inclusive) (base 1)
      */
     int end;
 
+    /**
+     * Constructor
+     * 
+     * @param seq
+     *          a sequence
+     * @param start
+     *          start position of matched range (base 1)
+     * @param end
+     *          end of matched range (inclusive, base 1)
+     */
     public Match(SequenceI seq, int start, int end)
     {
       sequence = seq;
@@ -79,7 +89,10 @@ public class SearchResults
     public String toString()
     {
       char[] chars = sequence.getSequence();
-      return String.valueOf(Arrays.copyOfRange(chars, start - 1, end));
+      // convert start/end to base 0 (with bounds check)
+      final int from = Math.max(start - 1, 0);
+      final int to = Math.min(end, chars.length + 1);
+      return String.valueOf(Arrays.copyOfRange(chars, from, to));
     }
   }