Example usage for java.util Collection containsAll

List of usage examples for java.util Collection containsAll

Introduction

In this page you can find the example usage for java.util Collection containsAll.

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

Returns true if this collection contains all of the elements in the specified collection.

Usage

From source file:org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils.java

/**
 * Check if the current user has all of the specified roles.
 * @param roles a comma-delimited list of role names
 * @return <code>true</code> if the user is authenticated and has all the roles
 *//*from   w  w w.j  ava  2 s  .  com*/
public static boolean ifAllGranted(final String roles) {
    Collection<GrantedAuthority> inferred = findInferredAuthorities(getPrincipalAuthorities());
    return inferred.containsAll(parseAuthoritiesString(roles));
}

From source file:nl.strohalm.cyclos.utils.access.PermissionHelper.java

/**
 * Used for query filter semantics with collections.<br>
 * Given a collection with the selected elements and another one with the allowed elements:<br>
 * If the allowed elements are empty (and empty for the allowed is not supported) it throws a PermissionDeniedException. Else, if elements is
 * empty, then allowed is returned. Otherwise, the selected elements must be contained in the allowed collection.
 *///w  w  w .java 2  s .c  o m
public static <T> Collection<T> checkSelection(final Collection<T> allowed, final Collection<T> selection,
        final boolean isEmptyAllowedSupported) {
    if (CollectionUtils.isEmpty(allowed)) {
        if (!isEmptyAllowedSupported || CollectionUtils.isNotEmpty(selection)) {
            throw new PermissionDeniedException();
        } else {
            return null;
        }
    }

    if (CollectionUtils.isEmpty(selection)) {
        return allowed;
    }
    if (!allowed.containsAll(selection)) {
        throw new PermissionDeniedException();
    }
    return selection;
}

From source file:ubic.gemma.analysis.expression.diff.DifferentialExpressionAnalysisUtil.java

/**
 * See if there are at least two samples for each factor value combination.
 * /*from  w  ww.ja  va 2  s  .c  om*/
 * @param expressionExperiment
 * @param factors
 * @return
 */
protected static boolean checkBiologicalReplicates(BioAssaySet expressionExperiment,
        Collection<ExperimentalFactor> factors) {

    Collection<BioMaterial> biomaterials = getBioMaterials(expressionExperiment);

    for (BioMaterial firstBm : biomaterials) {

        Collection<FactorValue> factorValuesToCheck = getRelevantFactorValues(factors, firstBm);

        boolean match = false;
        for (BioMaterial secondBm : biomaterials) {

            if (firstBm.equals(secondBm))
                continue;

            Collection<FactorValue> factorValuesToCompareTo = getRelevantFactorValues(factors, secondBm);

            if (factorValuesToCheck.size() == factorValuesToCompareTo.size()
                    && factorValuesToCheck.containsAll(factorValuesToCompareTo)) {
                log.debug("Replicate found for biomaterial " + firstBm + ".");
                match = true;
                break;
            }
        }
        if (!match) {
            log.warn("No replicate found for biomaterial " + firstBm + ".");
            return false;
        }
    }

    return true;

}

From source file:ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisUtil.java

/**
 * See if there are at least two samples for each factor value combination.
 *
 * @param expressionExperiment the experiment
 * @param factors              factors/*from  w w w  .j  a va2 s . co m*/
 * @return true if there are replicates
 */
static boolean checkBiologicalReplicates(BioAssaySet expressionExperiment,
        Collection<ExperimentalFactor> factors) {

    Collection<BioMaterial> biomaterials = DifferentialExpressionAnalysisUtil
            .getBioMaterials(expressionExperiment);

    for (BioMaterial firstBm : biomaterials) {

        Collection<FactorValue> factorValuesToCheck = DifferentialExpressionAnalysisUtil
                .getRelevantFactorValues(factors, firstBm);

        boolean match = false;
        for (BioMaterial secondBm : biomaterials) {

            if (firstBm.equals(secondBm))
                continue;

            Collection<FactorValue> factorValuesToCompareTo = DifferentialExpressionAnalysisUtil
                    .getRelevantFactorValues(factors, secondBm);

            if (factorValuesToCheck.size() == factorValuesToCompareTo.size()
                    && factorValuesToCheck.containsAll(factorValuesToCompareTo)) {
                DifferentialExpressionAnalysisUtil.log
                        .debug("Replicate found for biomaterial " + firstBm + ".");
                match = true;
                break;
            }
        }
        if (!match) {
            DifferentialExpressionAnalysisUtil.log.warn("No replicate found for biomaterial " + firstBm
                    + ", with factor values" + StringUtils.join(factorValuesToCheck, ","));
            return false;
        }
    }

    return true;

}

From source file:ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisUtil.java

/**
 * Returns true if all of the following conditions hold true: each biomaterial has more than 2 factor values, each
 * biomaterial has a factor value from one of the input factors paired with a factor value from the other input
 * factors, and all factor values from 1 factor have been paired with all factor values from the other factors,
 * across all biomaterials./*w w  w .j  a  va  2  s .c  o  m*/
 *
 * @param biomaterials        biomaterials
 * @param experimentalFactors exp. factors
 * @return false if not a complete block design.
 */
private static boolean checkBlockDesign(Collection<BioMaterial> biomaterials,
        Collection<ExperimentalFactor> experimentalFactors) {

    Collection<Set<FactorValue>> factorValuePairings = DifferentialExpressionAnalysisUtil
            .generateFactorValuePairings(experimentalFactors);

    /* check to see if the biomaterial's factor value pairing is one of the possible combinations */
    Map<Collection<FactorValue>, BioMaterial> seenPairings = new HashMap<>();
    for (BioMaterial m : biomaterials) {

        Collection<FactorValue> factorValuesFromBioMaterial = m.getFactorValues();

        if (factorValuesFromBioMaterial.size() < experimentalFactors.size()) {
            DifferentialExpressionAnalysisUtil.log.warn("Biomaterial must have at least "
                    + experimentalFactors.size() + "factor value.  Incomplete block design. " + m);
            return false;
        }

        /*
         * Find a combination of factors used in the model that this biomaterial has.
         */
        boolean ok = false;
        for (Set<FactorValue> pairing : factorValuePairings) {
            if (factorValuesFromBioMaterial.containsAll(pairing)) {
                ok = true;
                break;
            }
        }

        if (!ok) {
            /*
             * This amounts to a missing value.
             */
            throw new IllegalArgumentException(
                    "Biomaterial does not have a combination of factors matching the model; design error?: "
                            + m);
            // continue;
        }

        seenPairings.put(factorValuesFromBioMaterial, m);
    }
    if (seenPairings.size() != factorValuePairings.size()) {
        DifferentialExpressionAnalysisUtil.log.warn("Biomaterial not paired with all factor values for each of "
                + experimentalFactors.size() + " experimental factors.  Found " + seenPairings.size()
                + " pairings but should have " + factorValuePairings.size() + ".  Incomplete block design.");
        return false;
    }
    return true;

}

From source file:org.trnltk.testutil.testmatchers.ParseResultsExistMatcher.java

@Override
public boolean matchesSafely(Collection<String> item) {
    return item.containsAll(expectedParseResults);
}

From source file:ubic.gemma.analysis.expression.diff.DifferentialExpressionAnalysisUtil.java

/**
 * Returns true if all of the following conditions hold true: each biomaterial has more than 2 factor values, each
 * biomaterial has a factor value from one of the input factors paired with a factor value from the other input
 * factors, and all factor values from 1 factor have been paired with all factor values from the other factors,
 * across all biomaterials./*from  w  w w.  ja va  2 s. c  om*/
 * 
 * @param biomaterials
 * @param factorValues
 * @return false if not a complete block design.
 */
protected static boolean checkBlockDesign(Collection<BioMaterial> biomaterials,
        Collection<ExperimentalFactor> experimentalFactors) {

    Collection<Set<FactorValue>> factorValuePairings = generateFactorValuePairings(experimentalFactors);

    /* check to see if the biomaterial's factor value pairing is one of the possible combinations */
    Map<Collection<FactorValue>, BioMaterial> seenPairings = new HashMap<Collection<FactorValue>, BioMaterial>();
    for (BioMaterial m : biomaterials) {

        Collection<FactorValue> factorValuesFromBioMaterial = m.getFactorValues();

        if (factorValuesFromBioMaterial.size() < experimentalFactors.size()) {
            log.warn("Biomaterial must have at least " + experimentalFactors.size()
                    + "factor value.  Incomplete block design. " + m);
            return false;
        }

        /*
         * Find a combination of factors used in the model that this biomaterial has.
         */
        boolean ok = false;
        for (Set<FactorValue> pairing : factorValuePairings) {
            if (factorValuesFromBioMaterial.containsAll(pairing)) {
                ok = true;
                break;
            }
        }

        if (!ok) {
            /*
             * This amounts to a missing value.
             */
            throw new IllegalArgumentException(
                    "Biomaterial does not have a combination of factors matching the model; design error?: "
                            + m);
            // continue;
        }

        seenPairings.put(factorValuesFromBioMaterial, m);
    }
    if (seenPairings.size() != factorValuePairings.size()) {
        log.warn("Biomaterial not paired with all factor values for each of " + experimentalFactors.size()
                + " experimental factors.  Found " + seenPairings.size() + " pairings but should have "
                + factorValuePairings.size() + ".  Incomplete block design.");
        return false;
    }
    return true;

}

From source file:ru.anr.base.BaseParent.java

/**
 * Determines whether the given collection contains specified strings or
 * not. The parameter conjunction must be 'true' if we expect all strings to
 * be included in the source collection, otherwise it is 'false' (That means
 * at least one must be included)./*from   w w  w . j a  v  a 2s  .co  m*/
 * 
 * @param coll
 *            A source collection
 * @param conjunction
 *            true, if all inclusion are expected, or false, if at least
 *            one.
 * @param items
 *            Expected strings
 * @return true, if the given collection contains the specified items
 *         according to the condition 'conjunction'.
 */
protected static boolean contains(Collection<String> coll, boolean conjunction, String... items) {

    Set<String> s = set(items);
    return conjunction ? //
            coll.containsAll(list(items)) : //
            coll.stream().parallel().filter(a -> s.contains(a)).count() > 0;
}

From source file:com.collective.celos.ci.testing.fixtures.compare.FixTableComparer.java

private boolean equalsIgnoreOrder(Collection col1, Collection col2) {
    return col1.containsAll(col2) && col2.containsAll(col1);
}

From source file:org.simbasecurity.core.domain.repository.PolicyDatabaseRepositoryTest.java

@Test
public void find() {
    Collection<Policy> collection = policyDatabaseRepository.find(user);
    assertEquals(3, collection.size());//  ww  w  . jav a 2 s  . c o  m
    assertTrue(collection.containsAll(Arrays.asList(policy1, policy2, policy3)));
    assertFalse(collection.contains(policy4));
    assertFalse(collection.contains(policy5));
}