Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bigntallmike/99ee44870caae54d2b3ab797553c12cf to your computer and use it in GitHub Desktop.
Save bigntallmike/99ee44870caae54d2b3ab797553c12cf to your computer and use it in GitHub Desktop.
Alternative results merge
public class OrderedArrayList<T> {
private ArrayList<T> data;
private int searchpos;
public OrderedArrayList(ArrayList<T> data) {
this.data = data;
searchpos = 0;
}
public boolean contains(T other) {
for (int pos = searchpos; pos < data.size(); pos++) {
if (data.get(pos).equals(other)) {
searchpos = pos;
return true;
}
}
return false;
}
}
public ArrayList<T> getListIntersection(ArrayList<ArrayList<T>> ResultsList) {
final int baseid = getSmallest(ResultsList);
/* Allocate array for new data */
ArrayList<T> Matches = new ArrayList<>(ResultsList.get(baseid).size());
ArrayList<Integer> SearchResultsPos = new ArrayList<>(ResultsList.size());
for (int i=0; i<ResultsList.size(); i++) {
SearchResultsPos.add(0);
}
/* Now take the intersection of those lists, looping through one list and comparing: */
for (T Record : ResultsList.get(baseid)) {
boolean matched = true;
Log.d(TAG, "Checking " + Record.CUSTNUM);
for (int listid = 0; listid < ResultsList.size(); listid++) {
if (listid == baseid) {
break;
}
OrderedArrayList resultslist = new OrderedArrayList<T>(ResultsList.get(listid));
if (!resultslist.contains(Record)) {
matched = false;
break;
}
}
if (matched) {
Matches.add(Record);
}
}
Matches.trimToSize();
return Matches;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment