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

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

Introduction

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

Prototype

public static <E> Collection<E> intersection(final Collection<? extends E> a, final Collection<? extends E> b) 

Source Link

Document

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

Usage

From source file:net.femtoparsec.jwhois.gui.JWhoIsGUIModel.java

public JWhoIsGUIModel(GenericWhoIs<S> whoIs, JResultGUIFactory<S> jResultGUIFactory,
        Set<Source> proposedSources, Set<Source> selectedSources) {
    Validate.notNull(whoIs, "whoIs");
    Validate.notNull(jResultGUIFactory, "jResultGUIFactory");
    Validate.noNullElements(proposedSources, "proposedSources");
    Validate.notEmpty(proposedSources, "proposedSources");

    Validate.noNullElements(selectedSources, "selectedSources");

    this.whoIs = whoIs;
    this.proxy = null;
    this.jResultGUIFactory = jResultGUIFactory;
    this.preferredFormat = Format.RPSL;
    this.sources = new HashSet<Source>(proposedSources);
    this.selectedSources = new HashSet<Source>(CollectionUtils.intersection(proposedSources, selectedSources));
}

From source file:com.oltpbenchmark.util.ClassUtil.java

/**
 * //from ww w .jav  a2  s .  c  o m
 * @param <T>
 * @param target_class
 * @param params
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> Constructor<T> getConstructor(Class<T> target_class, Class<?>... params) {
    NoSuchMethodException error = null;
    try {
        return (target_class.getConstructor(params));
    } catch (NoSuchMethodException ex) {
        // The first time we get this it can be ignored
        // We'll try to be nice and find a match for them
        error = ex;
    }
    assert (error != null);

    if (LOG.isDebugEnabled()) {
        LOG.debug("TARGET CLASS:  " + target_class);
        LOG.debug("TARGET PARAMS: " + Arrays.toString(params));
    }

    List<Class<?>> paramSuper[] = (List<Class<?>>[]) new List[params.length];
    for (int i = 0; i < params.length; i++) {
        paramSuper[i] = ClassUtil.getSuperClasses(params[i]);
        if (LOG.isDebugEnabled())
            LOG.debug("  SUPER[" + params[i].getSimpleName() + "] => " + paramSuper[i]);
    } // FOR

    for (Constructor<?> c : target_class.getConstructors()) {
        Class<?> cTypes[] = c.getParameterTypes();
        if (LOG.isDebugEnabled()) {
            LOG.debug("CANDIDATE: " + c);
            LOG.debug("CANDIDATE PARAMS: " + Arrays.toString(cTypes));
        }
        if (params.length != cTypes.length)
            continue;

        for (int i = 0; i < params.length; i++) {
            List<Class<?>> cSuper = ClassUtil.getSuperClasses(cTypes[i]);
            if (LOG.isDebugEnabled())
                LOG.debug("  SUPER[" + cTypes[i].getSimpleName() + "] => " + cSuper);
            if (CollectionUtils.intersection(paramSuper[i], cSuper).isEmpty() == false) {
                return ((Constructor<T>) c);
            }
        } // FOR (param)
    } // FOR (constructors)
    throw new RuntimeException("Failed to retrieve constructor for " + target_class.getSimpleName(), error);
}

From source file:edu.brown.utils.ClassUtil.java

/**
 * Grab the constructor for the given target class with the provided input parameters.
 * This method will first try to find an exact match for the parameters, and if that
 * fails then it will be smart and try to find one with the input parameters super classes. 
 * @param <T>//  w w w .jav  a 2  s  .c  o  m
 * @param target_class
 * @param params
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> Constructor<T> getConstructor(Class<T> target_class, Class<?>... params) {
    NoSuchMethodException error = null;
    try {
        return (target_class.getConstructor(params));
    } catch (NoSuchMethodException ex) {
        // The first time we get this it can be ignored
        // We'll try to be nice and find a match for them
        error = ex;
    }
    assert (error != null);

    if (debug.val) {
        LOG.debug("TARGET CLASS:  " + target_class);
        LOG.debug("TARGET PARAMS: " + Arrays.toString(params));
    }

    final int num_params = (params != null ? params.length : 0);
    List<Class<?>> paramSuper[] = (List<Class<?>>[]) new List[num_params];
    for (int i = 0; i < num_params; i++) {
        paramSuper[i] = ClassUtil.getSuperClasses(params[i]);
        if (debug.val)
            LOG.debug("  SUPER[" + params[i].getSimpleName() + "] => " + paramSuper[i]);
    } // FOR

    for (Constructor<?> c : target_class.getConstructors()) {
        Class<?> cTypes[] = c.getParameterTypes();
        if (debug.val) {
            LOG.debug("CANDIDATE: " + c);
            LOG.debug("CANDIDATE PARAMS: " + Arrays.toString(cTypes));
        }
        if (params.length != cTypes.length)
            continue;

        for (int i = 0; i < num_params; i++) {
            List<Class<?>> cSuper = ClassUtil.getSuperClasses(cTypes[i]);
            if (debug.val)
                LOG.debug("  SUPER[" + cTypes[i].getSimpleName() + "] => " + cSuper);
            if (CollectionUtils.intersection(paramSuper[i], cSuper).isEmpty() == false) {
                return ((Constructor<T>) c);
            }
        } // FOR (param)
    } // FOR (constructors)
    throw new RuntimeException("Failed to retrieve constructor for " + target_class.getSimpleName(), error);
}

From source file:gov.nih.nci.cabig.ctms.suite.authorization.SuiteRoleMembership.java

private boolean intersectScope(ScopeType scopeType, SuiteRoleMembership other, SuiteRoleMembership to) {
    if (this.getRole().getScopes().contains(scopeType) && !other.getRole().getScopes().contains(scopeType)) {
        copyScope(scopeType, this, to);
    } else if (!this.getRole().getScopes().contains(scopeType)
            && other.getRole().getScopes().contains(scopeType)) {
        copyScope(scopeType, other, to);
    } else if (this.getRole().getScopes().contains(scopeType)) { // applicable to both
        if (this.isAll(scopeType)) {
            if (other.isAll(scopeType)) {
                to.forAll(scopeType);//  w  ww.j  ava2 s.c o m
            } else {
                copyScope(scopeType, other, to);
            }
        } else {
            if (other.isAll(scopeType)) {
                copyScope(scopeType, this, to);
            } else {
                Collection<String> scopeIntersection = CollectionUtils
                        .intersection(this.getIdentifiers(scopeType), other.getIdentifiers(scopeType));
                if (scopeIntersection.isEmpty()) {
                    return false;
                } else {
                    to.setIdentifiers(scopeType, new ArrayList<String>(scopeIntersection));
                }
            }
        }
    }
    return true;
}

From source file:org.drugis.addis.presentation.StudyGraphModel.java

/**
 * Return the studies with the correct indication and outcome that compare the given drugs.
 *//*  www.  j  a v  a 2 s .c o  m*/
public Collection<Study> getStudies(DrugSet a, DrugSet b) {
    return CollectionUtils.intersection(getStudies(a), getStudies(b));
}

From source file:org.drugis.addis.presentation.TreatmentDefinitionsGraphModel.java

/**
 * Return the studies with the correct indication and outcome that compare the given drugs.
 *//*from  ww  w.j a v  a 2s  . co  m*/
public Collection<Study> getStudies(TreatmentDefinition a, TreatmentDefinition b) {
    return CollectionUtils.intersection(getStudies(a), getStudies(b));
}

From source file:org.openanzo.client.RealtimeUpdateManager.java

/**
 * Finds all the tracker patterns that match the provided statements.
 * //w  w w  .j  av  a 2s  . c om
 * Implementation:
 * 
 * Trackers are stored as quads in a quad store, allowing the find operation to be use to find the matching trackers.
 * 
 * Nodes in a tracker pattern may be the special "ANY_URI", indicating the node in the quad is a wildcard.
 * 
 * The matching trackers are found as follows:
 * 
 * <pre>
 * (INTERSECTION
 *  (UNION trackers-with-matching-subject trackers-with-wildcard-subject)
 *  (UNION trackers-with-matching-predicate trackers-with-wildcard-predicate)
 *  (UNION trackers-with-matching-object trackers-with-wildcard-object)
 *  (UNION trackers-with-matching-namedGraphUri trackers-with-wildcard-namedGraphUri))
 * </pre>
 * 
 * @param statement
 *            The statement find matching tracker patterns for.
 * @return The tracker patterns matching the provided statement.
 */
protected Collection<Statement> findMatchingPatterns(Statement statement) {

    Collection<Statement> subjectExactMatches = quadStore.find(statement.getSubject(), null, null,
            (URI[]) null);
    Collection<Statement> subjectWildcardMatches = quadStore.find(Constants.ANY_URI, null, null, (URI[]) null);

    // UNION exact and wildcard matches of the statements subject
    Collection<Statement> subjectMatches = CollectionUtils.union(subjectExactMatches, subjectWildcardMatches);

    Collection<Statement> predicateExactMatches = quadStore.find(null, statement.getPredicate(), null,
            (URI[]) null);
    Collection<Statement> predicateWildcardMatches = quadStore.find(null, Constants.ANY_URI, null,
            (URI[]) null);

    // UNION exact and wildcard matches of the statements predicate
    Collection<Statement> predicateMatches = CollectionUtils.union(predicateExactMatches,
            predicateWildcardMatches);

    Collection<Statement> objectExactMatches = quadStore.find(null, null, statement.getObject(), (URI[]) null);
    Collection<Statement> objectWildcardMatches = quadStore.find(null, null, Constants.ANY_URI, (URI[]) null);

    // UNION exact and wildcard matches of the statements object
    Collection<Statement> objectMatches = CollectionUtils.union(objectExactMatches, objectWildcardMatches);

    Collection<Statement> namedGraphExactMatches = quadStore.find(null, null, null,
            statement.getNamedGraphUri());
    Collection<Statement> namedGraphWildcardMatches = quadStore.find(null, null, null, Constants.ANY_URI);

    // UNION exact and wildcard matches of the statements namedGraphUri
    Collection<Statement> namedGraphMatches = CollectionUtils.union(namedGraphExactMatches,
            namedGraphWildcardMatches);

    // INTERSECTION of the unions
    Collection<Statement> intersection = CollectionUtils.intersection(CollectionUtils.intersection(
            CollectionUtils.intersection(subjectMatches, predicateMatches), objectMatches), namedGraphMatches);

    return intersection;
}

From source file:proteinHypernetworkVisualization.implementation.jung.graphs.JungProteinComplexesGraph.java

public void setProteinComplexes(ProteinHypernetwork hypernetwork, Collection<Complex> complexes) {
    int index = 0;
    for (Complex c : complexes) {
        addVertex(c);/*from w  w  w  . j a va2s  .  c  om*/
    }

    // draw edges between overlapping complexes
    Complex[] cs = new Complex[complexes.size()];
    complexes.toArray(cs);
    for (int i = 0; i < cs.length; i++) {
        for (int j = i + 1; j < cs.length; j++) {
            int isize = CollectionUtils.intersection(cs[i], cs[j]).size();
            if (((float) isize) / (cs[i].size() + cs[j].size() - isize) > 0.2)
                addEdge(new Object(), cs[i], cs[j]);
        }
    }
}