Skip to content

Commit

Permalink
Address feedback. Initialize HashSet sizes to avoid resizing. Correct…
Browse files Browse the repository at this point in the history
… comment about indeterminante ordering.
  • Loading branch information
tdonohue committed Nov 1, 2023
1 parent 9c0bf08 commit f011a5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ public List<EPerson> allMembers(Context c, Group g) throws SQLException {

// Get all groups which are a member of this group
List<Group2GroupCache> group2GroupCaches = group2GroupCacheDAO.findByParent(c, g);
Set<Group> groups = new HashSet<>();
// Initialize HashSet based on List size to avoid Set resizing. See https://stackoverflow.com/a/21822273
Set<Group> groups = new HashSet<>((int) (group2GroupCaches.size() / 0.75 + 1));
for (Group2GroupCache group2GroupCache : group2GroupCaches) {
groups.add(group2GroupCache.getChild());
}
Expand All @@ -399,7 +400,9 @@ public List<EPerson> allMembers(Context c, Group g) throws SQLException {
public int countAllMembers(Context context, Group group) throws SQLException {
// Get all groups which are a member of this group
List<Group2GroupCache> group2GroupCaches = group2GroupCacheDAO.findByParent(context, group);
Set<Group> groups = new HashSet<>();
// Initialize HashSet based on List size + current 'group' to avoid Set resizing.
// See https://stackoverflow.com/a/21822273
Set<Group> groups = new HashSet<>((int) ((group2GroupCaches.size() + 1) / 0.75 + 1));
for (Group2GroupCache group2GroupCache : group2GroupCaches) {
groups.add(group2GroupCache.getChild());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public List<EPerson> search(Context context, String query, List<MetadataField> q
public int searchResultCount(Context context, String query, List<MetadataField> queryFields) throws SQLException;

/**
* Find all EPersons who are a member of one or more of the listed groups in a paginated fashion. Order is
* indeterminate.
* Find all EPersons who are a member of one or more of the listed groups in a paginated fashion. This returns
* EPersons ordered by UUID.
*
* @param context current Context
* @param groups Set of group(s) to check membership in
Expand Down

0 comments on commit f011a5a

Please sign in to comment.