2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
36 if (matches == null)
\r
38 matches = new Match[]
\r
40 new Match(seq, start, end)};
\r
44 int mSize = matches.length;
\r
46 Match[] tmp = new Match[mSize + 1];
\r
48 for (m = 0; m < mSize; m++)
\r
50 tmp[m] = matches[m];
\r
53 tmp[m] = new Match(seq, start, end);
\r
59 * This Method returns the search matches which lie between the
\r
60 * start and end points of the sequence in question. It is
\r
61 * optimised for returning objects for drawing on SequenceCanvas
\r
63 public int[] getResults(SequenceI sequence, int start, int end)
\r
65 if (matches == null)
\r
70 int[] result = null;
\r
74 for (int m = 0; m < matches.length; m++)
\r
76 if (matches[m].sequence == sequence)
\r
78 int matchStart = matches[m].sequence.findIndex(matches[m].start) - 1;
\r
79 int matchEnd = matches[m].sequence.findIndex(matches[m].end) - 1;
\r
81 if (matchStart <= end && matchEnd >= start)
\r
83 if (matchStart < start)
\r
97 matchStart, matchEnd};
\r
101 resultLength = result.length;
\r
102 tmp = new int[resultLength + 2];
\r
103 System.arraycopy(result, 0, tmp, 0, resultLength);
\r
105 result[resultLength] = matchStart;
\r
106 result[resultLength + 1] = matchEnd;
\r
114 public int getSize()
\r
116 return matches == null ? 0 : matches.length;
\r
119 public SequenceI getResultSequence(int index)
\r
121 return matches[index].sequence;
\r
124 public int getResultStart(int index)
\r
126 return matches[index].start;
\r
129 public int getResultEnd(int index)
\r
131 return matches[index].end;
\r
136 SequenceI sequence;
\r
140 public Match(SequenceI seq, int start, int end)
\r
143 this.start = start;
\r