Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Maeder2004-05-13 09:41:11 +0000
committerThomas Maeder2004-05-13 09:41:11 +0000
commitc1d690348df18d1e2f763369549256a27ce08dbd (patch)
tree9912d41a034e91541f291276710dbdb51736d0e5 /org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java
parent85827ce5b9cfe027e57dd53f2dee09ccc2114105 (diff)
downloadeclipse.platform.text-c1d690348df18d1e2f763369549256a27ce08dbd.tar.gz
eclipse.platform.text-c1d690348df18d1e2f763369549256a27ce08dbd.tar.xz
eclipse.platform.text-c1d690348df18d1e2f763369549256a27ce08dbd.zip
Diffstat (limited to 'org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java')
-rw-r--r--org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java30
1 files changed, 29 insertions, 1 deletions
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java
index 325f5d3783f..d786624313c 100644
--- a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java
+++ b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java
@@ -123,12 +123,40 @@ public abstract class AbstractTextSearchResult implements ISearchResult {
fElementsToMatches.put(match.getElement(), matches);
}
if (!matches.contains(match)) {
- matches.add(match);
+ insertSorted(matches, match);
return true;
}
return false;
}
+ private static void insertSorted(List matches, Match match) {
+ if (matches.size() == 0) {
+ matches.add(match);
+ return;
+ }
+ int insertIndex= getInsertIndex(matches, match, 0, matches.size());
+ matches.add(insertIndex, match);
+ }
+
+ private static int getInsertIndex(List matches, Match match, int min, int max) {
+ if (min == max)
+ return min;
+ int middle= (min+max)/2;
+ int compareResult= compare(match, (Match) matches.get(middle));
+ if (compareResult == 0)
+ return middle+1;
+ if (compareResult > 0)
+ return getInsertIndex(matches, match, min, middle);
+ return getInsertIndex(matches, match, middle+1, max);
+ }
+
+ private static int compare(Match match1, Match match2) {
+ int diff= match2.getOffset()-match1.getOffset();
+ if (diff != 0)
+ return diff;
+ return match2.getLength()-match1.getLength();
+ }
+
/**
* Removes all matches from this search result.
* <p>

Back to the top