public Collection<Group> getVisibleGroups(Group groupToCheck) {
        HashSet<String> groupNames;
        if (!provider.isSharingSupported()) {
            groupNames = new HashSet<>();
        } else {
            // Get all the public shared groups.
            groupNames = new HashSet<>(provider.getPublicSharedGroupNames());

            // Now get all visible groups to the given group.
            groupNames.addAll(provider.getVisibleGroupNames(groupToCheck.getName()));
        }
        return new GroupCollection(groupNames);
    }
Returns an unmodifiable Collection of all shared groups in the system for a given group name.

@param groupToCheck The group to check
@return an unmodifiable Collection of all shared groups for the given group name.
xmppserver/src/main/java/org/jivesoftware/openfire/group/GroupManager.java