Ejemplo n.º 1
0
 /**
  * Returns an unmodifiable Collection of all groups in the system.
  *
  * @return an unmodifiable Collection of all groups.
  */
 @SuppressWarnings("unchecked")
 public Collection<Group> getGroups() {
   Collection<String> groupNames = (Collection<String>) groupMetaCache.get(GROUP_NAMES_KEY);
   if (groupNames == null) {
     synchronized (GROUP_NAMES_KEY.intern()) {
       groupNames = (Collection<String>) groupMetaCache.get(GROUP_NAMES_KEY);
       if (groupNames == null) {
         groupNames = provider.getGroupNames();
         groupMetaCache.put(GROUP_NAMES_KEY, groupNames);
       }
     }
   }
   return new GroupCollection(groupNames);
 }
Ejemplo n.º 2
0
  /**
   * Returns an iterator for all groups that the entity with the specified JID is a member of.
   *
   * @param user the JID of the entity to get a list of groups for.
   * @return all groups that an entity belongs to.
   */
  @SuppressWarnings("unchecked")
  public Collection<Group> getGroups(JID user) {
    String key = user.toBareJID();

    Collection<String> groupNames = (Collection<String>) groupMetaCache.get(key);
    if (groupNames == null) {
      synchronized (key.intern()) {
        groupNames = (Collection<String>) groupMetaCache.get(key);
        if (groupNames == null) {
          groupNames = provider.getGroupNames(user);
          groupMetaCache.put(key, groupNames);
        }
      }
    }
    return new GroupCollection(groupNames);
  }
Ejemplo n.º 3
0
  /**
   * Returns all groups given a start index and desired number of results. This is useful to support
   * pagination in a GUI where you may only want to display a certain number of results per page. It
   * is possible that the number of results returned will be less than that specified by numResults
   * if numResults is greater than the number of records left in the system to display.
   *
   * @param startIndex start index in results.
   * @param numResults number of results to return.
   * @return an Iterator for all groups in the specified range.
   */
  @SuppressWarnings("unchecked")
  public Collection<Group> getGroups(int startIndex, int numResults) {
    String key = GROUP_NAMES_KEY + startIndex + "," + numResults;

    Collection<String> groupNames = (Collection<String>) groupMetaCache.get(key);
    if (groupNames == null) {
      synchronized (key.intern()) {
        groupNames = (Collection<String>) groupMetaCache.get(key);
        if (groupNames == null) {
          groupNames = provider.getGroupNames(startIndex, numResults);
          groupMetaCache.put(key, groupNames);
        }
      }
    }
    return new GroupCollection(groupNames);
  }