public boolean isGroupVisible(Group group, JID user) {
        SharedGroupVisibility showInRoster = group.getSharedWith();
        if (SharedGroupVisibility.everybody == showInRoster) {
            return true;
        }
        else if (SharedGroupVisibility.usersOfGroups == showInRoster) {
            if (group.isUser(user)) {
                 return true;
            }
            // Check if the user belongs to a group that may see this group
            Collection<Group> groupList = parseGroups(group.getSharedWithUsersInGroupNames());
            for (Group groupInList : groupList) {
                if (groupInList.isUser(user)) {
                    return true;
                }
            }
        }
        return false;
    }
Returns true if a given group is visible to a given user. That means, if the user can
see the group in his roster.

@param group the group to check if the user can see.
@param user the JID of the user to check if he may see the group.
@return true if a given group is visible to a given user.
xmppserver/src/main/java/org/jivesoftware/openfire/roster/RosterManager.java