- if (regex.searchFrom(noGaps, r))
- {
- resIndex = regex.matchedFrom();
- resIndex += residueOffset; // add back #residues before selection region
- int matchStartPosition = resIndex + seq.getStart();
- int matchEndPosition = matchStartPosition + regex.charsMatched()
- - 1;
- if (lastMatch == null || !lastMatch.contains(seq,
- matchStartPosition, matchEndPosition))
- {
- lastMatch = searchResults.addResult(seq, matchStartPosition,
- matchEndPosition);
- found = true;
- }
- if (!findAll)
- {
- resIndex++;
- return true;
- }
- r = resIndex;
- }
- else
- {
- break;
- }
+ columnIndex = visible.end + 1;
+ }
+
+ return false;
+ }
+
+ /**
+ * Adds the match held in the <code>searchPattern</code> Regex to the
+ * <code>searchResults</code>, unless it is a subregion of the last match
+ * recorded. <code>columnIndex</code> is advanced to the position after the
+ * start of the matched region, ready for the next search. Answers true if a
+ * match was added, else false.
+ *
+ * @param seq
+ * @param searchPattern
+ * @param firstResiduePosition
+ * @return
+ */
+ protected boolean recordMatch(SequenceI seq, Regex searchPattern,
+ int firstResiduePosition)
+ {
+ /*
+ * get start/end of the match in sequence coordinates
+ */
+ int offset = searchPattern.matchedFrom();
+ int matchStartPosition = firstResiduePosition + offset;
+ int matchEndPosition = matchStartPosition
+ + searchPattern.charsMatched() - 1;
+
+ /*
+ * update columnIndex to next column after the start of the match
+ * (findIndex returns a value base 1, columnIndex is held base 0)
+ */
+ columnIndex = seq.findIndex(matchStartPosition);
+
+ /*
+ * check that this match is not a subset of the previous one (JAL-2302)
+ */
+ List<SearchResultMatchI> matches = searchResults.getResults();
+ SearchResultMatchI lastMatch = matches.isEmpty() ? null
+ : matches.get(matches.size() - 1);
+
+ if (lastMatch == null || !lastMatch.contains(seq, matchStartPosition,
+ matchEndPosition))
+ {
+ searchResults.addResult(seq, matchStartPosition, matchEndPosition);
+ return true;