40
40
*/
41
41
public final class Groups {
42
42
43
+ /**
44
+ * Interface used to perform an action to a single group.
45
+ */
43
46
private interface Walker {
44
47
45
48
/**
46
49
* @param g group
47
- * @return true if traversing should end, false otherwise
50
+ * @return true if traversing should stop just after this group, false
51
+ * otherwise
48
52
*/
49
53
boolean call (Group g );
50
54
}
@@ -326,7 +330,19 @@ private static void deleteGroup(Set<Group> groups, String groupname) {
326
330
}
327
331
}
328
332
329
- private static boolean treeTraverseGroups (Set <Group > groups , Walker f ) {
333
+ /**
334
+ * Traverse the set of groups starting in top level groups (groups without a
335
+ * parent group) and performing depth first search in the group's subgroups.
336
+ *
337
+ * @param groups set of groups (mixed top level and other groups)
338
+ * @param walker an instance of {@link Walker} which is used for every
339
+ * traversed group
340
+ * @return true if {@code walker} emits true for any of the groups; false
341
+ * otherwise
342
+ *
343
+ * @see Walker
344
+ */
345
+ private static boolean treeTraverseGroups (Set <Group > groups , Walker walker ) {
330
346
LinkedList <Group > stack = new LinkedList <>();
331
347
for (Group g : groups ) {
332
348
// the flag here represents the group's depth in the group tree
@@ -340,7 +356,7 @@ private static boolean treeTraverseGroups(Set<Group> groups, Walker f) {
340
356
Group g = stack .getFirst ();
341
357
stack .removeFirst ();
342
358
343
- if (f .call (g )) {
359
+ if (walker .call (g )) {
344
360
return true ;
345
361
}
346
362
@@ -351,9 +367,17 @@ private static boolean treeTraverseGroups(Set<Group> groups, Walker f) {
351
367
return false ;
352
368
}
353
369
354
- private static boolean linearTraverseGroups (Set <Group > groups , Walker f ) {
370
+ /**
371
+ * Traverse the set of groups linearly based on the set's iterator.
372
+ *
373
+ * @param groups set of groups (mixed top level and other groups)
374
+ * @param walker an instance of {@link Walker} which is used for every
375
+ * traversed group
376
+ * @return true if {@code walker} emits true for any of the groups; false
377
+ */
378
+ private static boolean linearTraverseGroups (Set <Group > groups , Walker walker ) {
355
379
for (Group g : groups ) {
356
- if (f .call (g )) {
380
+ if (walker .call (g )) {
357
381
return true ;
358
382
}
359
383
}
0 commit comments