public static boolean isGroup(JID jid, boolean groupMustExist) throws GroupNotFoundException {
        boolean isGroup = false;
        String groupName = null, node = jid.getNode();
        if (node != null) {
            
            isGroup = (jid instanceof GroupJID) ? true :
                jid.getResource() != null &&
                StringUtils.isBase32(node) &&
                StringUtils.hash(groupName = decodeNode(node)).equals(jid.getResource());
            
            if (isGroup && groupMustExist) {
                Log.debug("Validating group: {}", jid);
                if (XMPPServer.getInstance().isLocal(jid)) {
                    GroupManager.getInstance().getGroup(groupName);
                } else {
                    isGroup = false;  // not in the local domain
                }
            }
        }
        return isGroup;
    }
Check a JID to determine whether it represents a group. If the given
JID is an instance of this class, it is a group JID. Otherwise,
calculate the hash to determine whether the JID can be resolved to
a group. This method also optionally validates that the corresponding 
group actually exists in the local domain.

@param jid A JID, possibly representing a group
@param groupMustExist If true, validate that the corresponding group actually exists
@return true if the given jid represents a group in the local domain
@throws GroupNotFoundException The JID represents a group, but the group does not exist
xmppserver/src/main/java/org/jivesoftware/openfire/group/GroupJID.java