summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2012-10-25 11:34:56 -0700
committerGerrit Code Review <noreply-gerritcodereview@google.com>2012-10-25 11:34:56 -0700
commitf360d97a6fbc6ff47776485f65b046409dfd761c (patch)
tree04bc84a98e756800150f907e59d2e854c64ec00b
parentf6717dc0cd78a5a419a7e9cef06a05bf09619e9c (diff)
parent3de0f1703ef4cfac5b468ecf44e08048d38988ad (diff)
Merge "Sort groups on the group list screen" into stable-2.5
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java28
1 files changed, 14 insertions, 14 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java
index 40372663b6..d3b2c8392c 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java
@@ -14,6 +14,8 @@
package com.google.gerrit.server.account;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import com.google.gerrit.common.data.GroupList;
import com.google.gerrit.common.data.GroupReference;
import com.google.gerrit.common.errors.NoSuchGroupException;
@@ -24,10 +26,10 @@ import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Set;
-import java.util.TreeSet;
public class VisibleGroups {
@@ -65,8 +67,7 @@ public class VisibleGroups {
public GroupList get(final Collection<ProjectControl> projects)
throws NoSuchGroupException {
- final Set<AccountGroup> groups =
- new TreeSet<AccountGroup>(new GroupComparator());
+ Map<AccountGroup.UUID, AccountGroup> groups = Maps.newHashMap();
for (final ProjectControl projectControl : projects) {
final Set<GroupReference> groupsRefs = projectControl.getAllGroups();
for (final GroupReference groupRef : groupsRefs) {
@@ -74,10 +75,10 @@ public class VisibleGroups {
if (group == null) {
throw new NoSuchGroupException(groupRef.getUUID());
}
- groups.add(group);
+ groups.put(group.getGroupUUID(), group);
}
}
- return createGroupList(filterGroups(groups));
+ return createGroupList(filterGroups(groups.values()));
}
/**
@@ -89,17 +90,15 @@ public class VisibleGroups {
public GroupList get(final IdentifiedUser user) throws NoSuchGroupException {
if (identifiedUser.get().getAccountId().equals(user.getAccountId())
|| identifiedUser.get().getCapabilities().canAdministrateServer()) {
- final Set<AccountGroup.UUID> effective =
- user.getEffectiveGroups().getKnownGroups();
- final Set<AccountGroup> groups =
- new TreeSet<AccountGroup>(new GroupComparator());
- for (final AccountGroup.UUID groupId : effective) {
+ Set<AccountGroup.UUID> mine = user.getEffectiveGroups().getKnownGroups();
+ Map<AccountGroup.UUID, AccountGroup> groups = Maps.newHashMap();
+ for (final AccountGroup.UUID groupId : mine) {
AccountGroup group = groupCache.get(groupId);
if (group != null) {
- groups.add(group);
+ groups.put(groupId, group);
}
}
- return createGroupList(filterGroups(groups));
+ return createGroupList(filterGroups(groups.values()));
} else {
throw new NoSuchGroupException("Groups of user '" + user.getAccountId()
+ "' are not visible.");
@@ -107,7 +106,7 @@ public class VisibleGroups {
}
private List<AccountGroup> filterGroups(final Iterable<AccountGroup> groups) {
- final List<AccountGroup> filteredGroups = new LinkedList<AccountGroup>();
+ final List<AccountGroup> filteredGroups = Lists.newArrayList();
final boolean isAdmin =
identifiedUser.get().getCapabilities().canAdministrateServer();
for (final AccountGroup group : groups) {
@@ -123,6 +122,7 @@ public class VisibleGroups {
}
filteredGroups.add(group);
}
+ Collections.sort(filteredGroups, new GroupComparator());
return filteredGroups;
}