private Map<JID, List<Group>> getSharedUsers(Collection<Group> sharedGroups) {
        final RosterManager rosterManager = XMPPServer.getInstance().getRosterManager();
        // Get the users to process from the shared groups. Users that belong to different groups
        // will have one entry in the map associated with all the groups
        Map<JID, List<Group>> sharedGroupUsers = new HashMap<>();
        for (Group group : sharedGroups) {
            // Get all the users that should be in this roster
            Collection<JID> users = rosterManager.getSharedUsersForRoster(group, this);
            // Add the users of the group to the general list of users to process
            JID userJID = getUserJID();
            for (JID jid : users) {
                // Add the user to the answer if the user doesn't belong to the personal roster
                // (since we have already added the user to the answer)
                boolean isRosterItem = rosterItems.containsKey(jid.toBareJID());
                if (!isRosterItem && !userJID.equals(jid)) {
                    List<Group> groups = sharedGroupUsers.get(jid);
                    if (groups == null) {
                        groups = new ArrayList<>();
                        sharedGroupUsers.put(jid, groups);
                    }
                    groups.add(group);
                }
            }
        }
        return sharedGroupUsers;
    }
Returns the list of users that belong ONLY to a shared group of this user. If the contact
belongs to the personal roster and a shared group then it wont' be included in the answer.

@param sharedGroups the shared groups of this user.
@return the list of users that belong ONLY to a shared group of this user.
xmppserver/src/main/java/org/jivesoftware/openfire/roster/Roster.java