X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSearchResults.java;h=e62e58a8192f0ab64f351a8ab005568ca53ca6ec;hb=9ad1e437d5d6366f0b06fbfbdb446a720ca57104;hp=7a241fde94ae63e1c822451831ddb443f16482b4;hpb=10ff37d2cb03f342ddbed679951d3e2fef0a404b;p=jalview.git diff --git a/src/jalview/datamodel/SearchResults.java b/src/jalview/datamodel/SearchResults.java index 7a241fd..e62e58a 100755 --- a/src/jalview/datamodel/SearchResults.java +++ b/src/jalview/datamodel/SearchResults.java @@ -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. * @@ -21,6 +21,7 @@ package jalview.datamodel; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -39,10 +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; @@ -64,6 +81,19 @@ public class SearchResults { return end; } + + /** + * Returns the string of characters in the matched region. + */ + @Override + public String toString() + { + char[] chars = sequence.getSequence(); + // 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)); + } } /** @@ -228,4 +258,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(); + } }