Sort change owner first in ApprovalTable
I68cd21e4 claimed to do this but clearly did not. Change-Id: I3885c898dfeacc83a4b55ee2a2270bbb293774d9
This commit is contained in:
@@ -18,6 +18,8 @@ import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -26,12 +28,18 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ApprovalDetail {
|
||||
public static final Comparator<ApprovalDetail> SORT =
|
||||
new Comparator<ApprovalDetail>() {
|
||||
public int compare(ApprovalDetail o1, ApprovalDetail o2) {
|
||||
return o1.hasNonZero - o2.hasNonZero;
|
||||
}
|
||||
};
|
||||
public static List<ApprovalDetail> sort(Collection<ApprovalDetail> ads,
|
||||
final int owner) {
|
||||
List<ApprovalDetail> sorted = new ArrayList<ApprovalDetail>(ads);
|
||||
Collections.sort(sorted, new Comparator<ApprovalDetail>() {
|
||||
public int compare(ApprovalDetail o1, ApprovalDetail o2) {
|
||||
int byOwner = (o2.account.get() == owner ? 1 : 0)
|
||||
- (o1.account.get() == owner ? 1 : 0);
|
||||
return byOwner != 0 ? byOwner : (o1.hasNonZero - o2.hasNonZero);
|
||||
}
|
||||
});
|
||||
return sorted;
|
||||
}
|
||||
|
||||
protected Account.Id account;
|
||||
protected List<PatchSetApproval> approvals;
|
||||
|
@@ -53,7 +53,6 @@ import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -157,11 +156,9 @@ public class ApprovalTable extends Composite {
|
||||
} else {
|
||||
displayHeader(change.labels());
|
||||
table.resizeRows(1 + byUser.size());
|
||||
List<ApprovalDetail> sorted =
|
||||
new ArrayList<ApprovalDetail>(byUser.values());
|
||||
Collections.sort(sorted, ApprovalDetail.SORT);
|
||||
int i = 1;
|
||||
for (ApprovalDetail ad : sorted) {
|
||||
for (ApprovalDetail ad : ApprovalDetail.sort(
|
||||
byUser.values(), change.owner()._account_id())) {
|
||||
displayRow(i++, ad, change, accounts.get(ad.getAccount().get()));
|
||||
}
|
||||
table.setVisible(true);
|
||||
|
Reference in New Issue
Block a user