Merge "Prevent crash when removing duplicates" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7a148b9e09
@@ -323,18 +323,18 @@ public class DatabaseResultLoader extends AsyncLoader<List<? extends SearchResul
|
||||
for (int j = i - 1; j >= 0; j--) {
|
||||
primaryResult = results.get(j);
|
||||
if (areDuplicateResults(primaryResult, secondaryResult)) {
|
||||
|
||||
if (primaryResult.viewType != ResultPayload.PayloadType.INTENT) {
|
||||
// Case where both payloads are inline
|
||||
results.remove(i);
|
||||
break;
|
||||
} else if (secondaryResult.viewType != ResultPayload.PayloadType.INTENT) {
|
||||
// Case where only second result is inline
|
||||
// Case where only second result is inline.
|
||||
results.remove(j);
|
||||
i--; // shift the top index to reflect the lower element being removed
|
||||
} else {
|
||||
// Case where both payloads are intent
|
||||
// Case where both payloads are intent.
|
||||
results.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -378,6 +378,47 @@ public class DatabaseResultLoaderTest {
|
||||
assertThat(results.get(3)).isEqualTo(resultFive);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeDupe_threeDuplicates_onlyOneStays() {
|
||||
/*
|
||||
* Create a list as follows:
|
||||
* (3) Intent One
|
||||
* (2) Intent One
|
||||
* (1) Intent One
|
||||
*
|
||||
* After removing duplicates:
|
||||
* (1) Intent One
|
||||
*/
|
||||
List<SearchResult> results = new ArrayList();
|
||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
||||
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
// Intent One
|
||||
builder.addTitle(titleOne)
|
||||
.addSummary(summaryOne)
|
||||
.addPayload(intentPayload);
|
||||
SearchResult resultOne = builder.build();
|
||||
results.add(resultOne);
|
||||
|
||||
// Intent Two
|
||||
builder.addTitle(titleOne)
|
||||
.addSummary(summaryOne)
|
||||
.addPayload(intentPayload);
|
||||
SearchResult resultTwo = builder.build();
|
||||
results.add(resultTwo);
|
||||
|
||||
// Intent Three
|
||||
builder.addTitle(titleOne)
|
||||
.addSummary(summaryOne)
|
||||
.addPayload(intentPayload);
|
||||
SearchResult resultThree = builder.build();
|
||||
results.add(resultThree);
|
||||
|
||||
loader = new DatabaseResultLoader(mContext, "", null);
|
||||
loader.removeDuplicates(results);
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseTwoWords_firstWordMatches_ranksHigher() {
|
||||
final String caseOne = "Apple pear";
|
||||
|
Reference in New Issue
Block a user