Example usage for org.apache.commons.collections CollectionUtils intersection

List of usage examples for org.apache.commons.collections CollectionUtils intersection

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils intersection.

Prototype

public static Collection intersection(final Collection a, final Collection b) 

Source Link

Document

Returns a Collection containing the intersection of the given Collection s.

Usage

From source file:org.sipfoundry.sipxconfig.site.acd.AcdPresenceServer.java

public void pageBeginRender(PageEvent event) {
    if (!isAcdServerPresent()) {
        return;//from www  . j  a v  a2 s.  c om
    }

    List allowedUsers = getAllowedUsers();
    if (allowedUsers == null) {
        allowedUsers = getAcdContext().getUsersWithAgents();
        setAllowedUsers(allowedUsers);
    }

    List acdServers = getAcdContext().getServers();
    if (getCurrentLocationId() == 0) {
        setCurrentLocationId(((AcdServer) acdServers.get(0)).getLocation().getId());
    }

    Location location = getLocationsManager().getLocation(getCurrentLocationId());
    List usersOnThisServer = getAcdContext().getUsersWithAgentsForLocation(location);
    Collection<User> users = CollectionUtils.intersection(usersOnThisServer, allowedUsers);
    setUsers(Arrays.asList(users.toArray()));

    if (getUserStatuses() == null) {
        setUserStatuses(new HashMap(users.size()));
    }
    setLocationSelectionModel(new LocationSelectionModel(acdServers));
}

From source file:org.sipfoundry.sipxconfig.site.acd.AcdSupervisorConsole.java

public void pageBeginRender(PageEvent event) {
    AcdContext context = getAcdContext();
    if (getAcdServerId() == null || !context.isAcdServerIdValid(getAcdServerId())) {
        // make user pick a server iff there's more than 1
        List servers = context.getServers();
        if (servers.size() != 1) {
            setEffectiveTab("selectServer");
            return;
        }/* www  .  j  av  a  2  s .  c  o m*/
        setAcdServerId(((AcdServer) servers.get(0)).getId());
    }

    setEffectiveTab(getTab());

    AcdServer server = getAcdServer();
    if (server == null) {
        server = context.loadServer(getAcdServerId());
        setAcdServer(server);
    }

    AcdStatistics stats = getAcdStatistics();
    if (stats == null) {
        stats = new AcdStatistics();
        stats.setAcdContext(getAcdContext());

        CoreContext core = getCoreContext();
        Integer userId = getUserSession().getUserId();
        User supervisor = core.loadUser(userId);

        List<User> supervisedUsers = core.getUsersThatISupervise(supervisor);
        List usersWithAgents = context.getUsersWithAgents();
        Collection<User> supervisedAgents = CollectionUtils.intersection(supervisedUsers, usersWithAgents);

        stats.setUsers(supervisedAgents);
        Collection<AcdQueue> queues = context.getQueuesForUsers(server, supervisedAgents);
        for (Object acdServerObj : context.getServers()) {
            AcdServer acdServer = (AcdServer) acdServerObj;
            if (acdServer.getId() != server.getId()) {
                queues.addAll(context.getQueuesForUsers(acdServer, supervisedAgents));
            }
        }

        stats.setQueues(queues);

        setSupervisedUsers(supervisedAgents);

        setAcdStatistics(stats);
    } else if (server.getId() != getAcdServerId()) {
        server = context.loadServer(getAcdServerId());
        setAcdServer(server);
    }
}

From source file:org.sonatype.nexus.ldap.internal.connector.DefaultLdapConnector.java

public SortedSet<LdapUser> searchUsers(String username, Set<String> roleIds) throws LdapDAOException {
    LdapContext context = null;//from  w w w  .j  ava 2  s. c om
    try {
        context = this.getLdapContextFactory().getSystemLdapContext();
        LdapAuthConfiguration conf = this.getLdapAuthConfiguration();

        // make sure the username is at least an empty string
        if (username == null) {
            username = "";
        }

        // is this a role-based search?
        if (roleIds != null && !roleIds.isEmpty()) {

            // do we have any roles to check?
            if (!conf.isLdapGroupsAsRoles()) {
                return new TreeSet<>();
            }

            // searchUsers is expensive with static mapping, so check roles exist in LDAP first
            if (isStaticGroupMapping(conf) && CollectionUtils.intersection( //
                    roleIds, ldapGroupManager.getAllGroups(context, conf)).isEmpty()) {
                return new TreeSet<>();
            }
        }

        SortedSet<LdapUser> users = this.ldapUserManager.getUsers(username + "*", context, conf, -1);

        // only need to update membership when using static mapping
        if (isStaticGroupMapping(conf)) {
            for (LdapUser ldapUser : users) {
                updateGroupMembership(context, conf, ldapUser);
            }
        }

        return users;
    } catch (NamingException e) {
        String message = "Failed to retrieve ldap information for users.";
        throw new LdapDAOException(message, e);
    } finally {
        this.closeContext(context);
    }
}

From source file:org.springjutsu.validation.context.ValidationGroupContextHandler.java

/**
 * Validation groups are active if any /* w w w.j  a  v  a  2 s . co  m*/
 * of the specified qualifiers is an exact 
 * match to any of the currently specified
 * validation hints (group names)
 */
@Override
public boolean isActive(Set<String> qualifiers, Object rootModel, String[] validationHints) {
    return !CollectionUtils.intersection(qualifiers, Arrays.asList(validationHints)).isEmpty();
}

From source file:org.topicquests.solr.agents.merge.BasePortfolioAgent.java

/**
 * <p>Compare node type or subOf to see if <code>theHit</code>
 * is the same as <code>theNode</code>. There is no sense in
 * doing any other test if the nodes are not of the same type.</p>
 * @param theHit/*from   w w  w .j  a  va 2s. c o  m*/
 * @return <code>true</code> if the same type
 */
public boolean compareNodeTypes(INode theHit) {
    String aType = theNode.getNodeType();
    String bType = theHit.getNodeType();
    agentEnvironment.logDebug("BasePortfolioAgent.compareNodeTypes-1 " + aType + " " + bType);

    if (aType == null && bType == null) {
        //must test subclasses
        List<String> aSubs = theNode.listSuperclassIds();
        List<String> bSubs = theHit.listSuperclassIds();
        agentEnvironment.logDebug("BasePortfolioAgent.compareNodeTypes-2 " + aSubs + " " + bSubs);
        if (aSubs.isEmpty() && bSubs.isEmpty())
            //the case where these are untyped nodes; let the mergers fly!
            return true;
        else {
            Collection<String> ctr = CollectionUtils.intersection(aSubs, bSubs);
            //require that the intersection of two same-sized collections
            // be the same size: they each contain the same values
            if (!ctr.isEmpty())
                return (ctr.size() == aSubs.size());

        }
    } else if (aType != null && bType != null && aType.equals(bType))
        return true;

    return false;
}

From source file:org.topicquests.solr.agents.merge.BasePortfolioAgent.java

/**
 * <p>Deal with this <code>hitNode</code></p>
 * <p>Note: this deals with merge comparisons where language-based objects,
 * e.g. labels or details, are in play</p>
 * @param hitNode// w w w  .j  a  v a 2 s.c om
 * @param objects
 * @param language
 * @param baseField
 */
public void addToHits(INode hitNode, List<String> objects, String language, String baseField) {
    Map<String, Object> o = hits.get(hitNode);

    if (o == null) {
        o = new HashMap<String, Object>();
        o.put("numHits", new Integer(0));
        o.put("votes", new Double(0));
        hits.put(hitNode, o);
    }
    Integer ix = (Integer) o.get("numHits");
    int iix = ix.intValue();
    iix++;
    o.put("numHits", new Integer(iix));
    List<String> labs = null;
    if (baseField.equals(ITopicQuestsOntology.LABEL_PROPERTY))
        labs = hitNode.listLabels(language);
    else if (baseField.equals(ITopicQuestsOntology.DETAILS_PROPERTY))
        labs = hitNode.listDetails(language);
    else {
        agentEnvironment.logError("BasePortfolioAgent.addToHits bad baseField " + baseField, null);
        return;
    }
    agentEnvironment.logDebug("BasePortfolioAgent.addToHits- " + labs);
    Collection<String> inters = CollectionUtils.intersection(objects, labs);
    int count = inters.size();
    //we cannot be here if count = 0
    double vote = (double) count / (double) objects.size();
    Double d = (Double) o.get("votes");
    double dd = d.doubleValue();
    dd += vote;
    o.put("votes", new Double(dd));
    agentEnvironment.logDebug("BasePortfolioAgent.addToHits-1 " + hits);
}

From source file:org.topicquests.solr.SolrDataProvider.java

/**
 * Utility method to accept or reject a node based on privacy and credentials
 * @param n/*from  w w  w . j  a v a 2  s  .c o m*/
 * @param credentials
 * @return
 */
INode testNodeForCredentials(INode n, Set<String> credentials) {
    INode result = n;
    if (n.getIsPrivate()) {
        //         System.out.println("XXXX-1");
        List<String> creds = n.listRestrictionCredentials();
        //         System.out.println("testnodeforcredentials-1 "+n.getLocator()+" "+creds+" "+credentials);
        Collection<String> x = CollectionUtils.intersection(credentials, creds);
        if (x.isEmpty())
            result = null;
    }
    return result;
}

From source file:org.topicquests.solr.SolrDataProvider.java

/**
 * Will always return false if private node and <code>credentials = null</code>
 * @param node//from   ww  w  .  j av a2  s  .  c  o m
 * @param credentials
 * @return
 */
boolean isSafe(Map<String, Object> node, Set<String> credentials) {
    System.out.println("ISSAFE- " + node.get(ITopicQuestsOntology.LOCATOR_PROPERTY) + " "
            + node.get(ITopicQuestsOntology.IS_PRIVATE_PROPERTY));
    Boolean isPrivate = (Boolean) node.get(ITopicQuestsOntology.IS_PRIVATE_PROPERTY);
    if (isPrivate == null) // rare event; need to understand what's going on
        log.logError("SolrDataProvider.isSafe bad boolean " + node, null);
    else if (isPrivate) {
        if (credentials == null)
            return false;
        Object o = node.get(ITopicQuestsOntology.RESTRICTION_PROPERTY_TYPE);
        if (o == null) {
            //only option is to see if credentials include userId
            String creatorId = (String) node.get(ITopicQuestsOntology.CREATOR_ID_PROPERTY);
            return credentials.contains(creatorId);
        } else {
            List<String> acls = (List<String>) o;
            Collection<String> x = CollectionUtils.intersection(credentials, acls);
            return x.isEmpty();
        }
    }
    return true; // default
}

From source file:org.xwiki.model.reference.EntityReferenceSet.java

private boolean matchesExclude(EntityReference reference) {
    if (this.excludes == null) {
        return true;
    }/*from w ww  .  ja  va  2 s . c o m*/

    EntityReferenceEntry currentEntry = this.excludes;
    for (EntityReference element : reference.getReversedReferenceChain()) {
        // No children
        if (currentEntry.children == null) {
            return false;
        }

        EntityReferenceEntryChildren typedChildren = currentEntry.children.get(element.getType());

        if (typedChildren != null) {
            // Children have same type
            EntityReferenceEntry nameEntry = typedChildren.children.get(element.getName());

            if (nameEntry == null) {
                currentEntry = typedChildren.children.get(null);

                if (currentEntry == null) {
                    return true;
                }
            } else {
                currentEntry = nameEntry;
            }

            if (!currentEntry.matches(element)) {
                return true;
            }
        }
    }

    // Check if the reference is shorter than the exclude(s)
    return currentEntry.children != null
            // Check if the excluded parameters are the same as the one the reference contains
            || (currentEntry.parameters != null
                    && CollectionUtils.intersection(getParametersKeys(currentEntry.parameters),
                            reference.getParameters().keySet()).isEmpty());
}

From source file:pl.edu.icm.coansys.disambiguation.work.comparator.WorkAuthorComparator.java

boolean commonAuthorNames(DocumentWrapper doc1, DocumentWrapper doc2) {
    List<String> doc1AuthorNames = extractAuthorNames(doc1);
    List<String> doc2AuthorNames = extractAuthorNames(doc2);

    int authorsNumber = Math.min(doc1AuthorNames.size(), doc2AuthorNames.size());
    int commonNamesNumber = CollectionUtils.intersection(doc1AuthorNames, doc2AuthorNames).size();
    if (commonNamesNumber == authorsNumber) {
        return true;
    }/*from  ww  w  .  j ava2  s  . co m*/
    return false;
}