Skip to content

Commit 3055ad6

Browse files
authored
Merge pull request #1651 from tulinkry/groups-dedup
deduplicating code in RuntimeEnvironment and ProjectHelper
2 parents 8c1c954 + 8453d6d commit 3055ad6

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/org/opensolaris/opengrok/configuration/Group.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,18 @@ public static Group getByName(String name) {
284284
}
285285
return ret;
286286
}
287+
288+
/**
289+
* Reduce the group set to only those which match the given project based on
290+
* the project's description.
291+
*
292+
* @param project the project
293+
* @param groups set of groups
294+
* @return set of groups matching the project
295+
*/
296+
public static Set<Group> matching(Project project, Set<Group> groups) {
297+
Set<Group> copy = new TreeSet<>(groups);
298+
copy.removeIf((g) -> !g.match(project));
299+
return copy;
300+
}
287301
}

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,13 +1234,7 @@ private void populateGroups(Set<Group> groups, Set<Project> projects) {
12341234
}
12351235
for (Project project : projects) {
12361236
// filterProjects only groups which match project's description
1237-
Set<Group> copy = new TreeSet<>(groups);
1238-
copy.removeIf(new Predicate<Group>() {
1239-
@Override
1240-
public boolean test(Group g) {
1241-
return !g.match(project);
1242-
}
1243-
});
1237+
Set<Group> copy = Group.matching(project, groups);
12441238

12451239
// add project to the groups
12461240
for (Group group : copy) {

src/org/opensolaris/opengrok/web/ProjectHelper.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,7 @@ private void populateGroups() {
128128
groups.addAll(cfg.getEnv().getGroups());
129129
for (Project project : cfg.getEnv().getProjectList()) {
130130
// filterProjects only groups which match project's description
131-
Set<Group> copy = new TreeSet<>(groups);
132-
copy.removeIf(new Predicate<Group>() {
133-
@Override
134-
public boolean test(Group g) {
135-
return !g.match(project);
136-
}
137-
});
131+
Set<Group> copy = Group.matching(project, groups);
138132

139133
// if no group matches the project, add it to not-grouped projects
140134
if (copy.isEmpty()) {

0 commit comments

Comments
 (0)