2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.datamodel;
\r
21 public class SearchResults
\r
27 * This method replaces the old search results which merely
\r
28 * held an alignment index of search matches. This broke
\r
29 * when sequences were moved around the alignment
\r
30 * @param seq Sequence
\r
34 public void addResult(SequenceI seq, int start, int end)
\r
38 matches = new Match[]{new Match(seq, start, end)};
\r
42 int mSize = matches.length;
\r
44 Match [] tmp = new Match[mSize+1];
\r
46 for(m=0; m<mSize; m++)
\r
48 tmp[m] = matches[m];
\r
51 tmp[m] = new Match(seq, start, end);
\r
57 * This Method returns the search matches which lie between the
\r
58 * start and end points of the sequence in question. It is
\r
59 * optimised for returning objects for drawing on SequenceCanvas
\r
61 public int [] getResults(SequenceI sequence, int start, int end)
\r
66 int [] result = null;
\r
70 for(int m=0; m<matches.length; m++)
\r
72 if( matches[m].sequence == sequence )
\r
74 int matchStart = matches[m].sequence.findIndex( matches[m].start ) - 1;
\r
75 int matchEnd = matches[m].sequence.findIndex( matches[m].end ) - 1;
\r
77 if(matchStart<=end && matchEnd>=start)
\r
79 if(matchStart<start)
\r
87 result = new int[]{matchStart, matchEnd};
\r
90 resultLength = result.length;
\r
91 tmp = new int[resultLength+2];
\r
92 System.arraycopy(result,0,tmp,0,resultLength);
\r
94 result[resultLength] = matchStart;
\r
95 result[resultLength+1] = matchEnd;
\r
103 public int getSize()
\r
105 return matches==null ? 0 : matches.length;
\r
108 public SequenceI getResultSequence(int index)
\r
109 { return matches[index].sequence; }
\r
111 public int getResultStart(int index)
\r
112 { return matches[index].start; }
\r
114 public int getResultEnd(int index)
\r
115 { return matches[index].end; }
\r
119 SequenceI sequence;
\r
123 public Match(SequenceI seq, int start, int end)
\r
126 this.start = start;
\r