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.cloudifysource.rest.security.CustomPermissionEvaluator.java

private boolean hasAllAuthGroups(final Collection<String> requestedAuthGroups) {
    boolean isPermitted = false;

    Collection<String> userAuthGroups = getUserAuthGroups();
    if (userAuthGroups.containsAll(requestedAuthGroups)) {
        isPermitted = true;/*from  www . j  av  a 2 s . c  o  m*/
    }

    return isPermitted;
}

From source file:org.apache.hadoop.util.TestStringUtils.java

@Test
public void testGetUniqueNonEmptyTrimmedStrings() {
    final String TO_SPLIT = ",foo, bar,baz,,blah,blah,bar,";
    Collection<String> col = StringUtils.getTrimmedStringCollection(TO_SPLIT);
    assertEquals(4, col.size());// w  ww . ja  va2 s . c  o  m
    assertTrue(col.containsAll(Arrays.asList(new String[] { "foo", "bar", "baz", "blah" })));
}

From source file:pt.ist.expenditureTrackingSystem.domain.acquisitions.Financer.java

public boolean hasAllInvoicesAllocated() {
    Collection<PaymentProcessInvoice> allocatedInvoices = getAllocatedInvoices();
    for (UnitItem unitItem : getUnitItems()) {
        if (!allocatedInvoices.containsAll(unitItem.getConfirmedInvoices())) {
            return false;
        }//  ww w. ja  va 2  s  .co  m
    }
    return true;
}

From source file:edu.uci.ics.asterix.optimizer.rules.PushGroupByThroughProduct.java

private PushTestResult canPushThrough(GroupByOperator gby, ILogicalOperator branch,
        List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> toPush,
        List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> notToPush) throws AlgebricksException {
    Collection<LogicalVariable> fromBranch = new HashSet<LogicalVariable>();
    VariableUtilities.getLiveVariables(branch, fromBranch);
    Collection<LogicalVariable> usedInGbyExprList = new ArrayList<LogicalVariable>();
    for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getGroupByList()) {
        p.second.getValue().getUsedVariables(usedInGbyExprList);
    }//from  w w w . j a v a 2  s  .co  m

    if (!fromBranch.containsAll(usedInGbyExprList)) {
        return PushTestResult.FALSE;
    }
    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    for (ILogicalPlan p : gby.getNestedPlans()) {
        for (Mutable<ILogicalOperator> r : p.getRoots()) {
            OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) r.getValue(), free);
        }
    }
    if (!fromBranch.containsAll(free)) {
        return PushTestResult.FALSE;
    }

    Set<LogicalVariable> decorVarRhs = new HashSet<LogicalVariable>();
    decorVarRhs.clear();
    for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getDecorList()) {
        ILogicalExpression expr = p.second.getValue();
        if (expr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
            return PushTestResult.FALSE;
        }
        VariableReferenceExpression varRef = (VariableReferenceExpression) expr;
        LogicalVariable v = varRef.getVariableReference();
        if (decorVarRhs.contains(v)) {
            return PushTestResult.REPEATED_DECORS;
        }
        decorVarRhs.add(v);

        if (fromBranch.contains(v)) {
            toPush.add(p);
        } else {
            notToPush.add(p);
        }
    }
    return PushTestResult.TRUE;
}

From source file:org.intermine.pathquery.LogicExpression.java

/**
 * Validates an expression for the given groups of codes, making sure each group is only
 * ANDed together. Returns either this or an alternative LogicExpression.
 *
 * @param variables a List of Collections of String variable names
 * @return a new LogicExpression/*from ww  w  .  j  a v  a2s .c o  m*/
 */
public LogicExpression validateForGroups(List<? extends Collection<String>> variables) {
    // First, check whether the expression is already valid
    try {
        split(variables);
        return this;
    } catch (IllegalArgumentException e) {
    }
    // It is not valid, so alter it.
    Set<String> presentVariables = new HashSet<String>();
    for (Collection<String> v : variables) {
        for (String var : v) {
            if (presentVariables.contains(var)) {
                throw new IllegalArgumentException("There is an overlap in variables");
            }
            presentVariables.add(var);
        }
    }
    if (!presentVariables.equals(getVariableNames())) {
        throw new IllegalArgumentException("Variables in argument (" + presentVariables
                + ") do not match variables in expression (" + getVariableNames() + ")");
    }
    List<String> subLogics = new ArrayList<String>();
    for (Collection<String> group : variables) {
        if (group.containsAll(presentVariables)) {
            // In this case all constraints are lumped together, but cannot be or-ed.
            subLogics = new ArrayList<String>(Arrays.asList(StringUtils.join(group, " and ")));
        } else {
            LogicExpression copy = new LogicExpression(toString());
            try {
                copy.removeAllVariablesExcept(group);
                subLogics.add("(" + copy + ")");
            } catch (IllegalArgumentException e) {
                // Must have removed all variables
            }
        }
    }
    String retval = StringUtils.join(subLogics, " and ");
    return new LogicExpression(retval);
}

From source file:nl.mpi.lamus.workspace.upload.implementation.LamusWorkspaceUploadHelperTest.java

@Test
public void assureLinksPidMetadataReference_FailedLink()
        throws URISyntaxException, MalformedURLException, IOException, MetadataException, WorkspaceException {

    final String parentFilename = "parent.cmdi";
    final URI parentFileURI = new URI("file:/workspaces/" + workspaceID + "/upload/" + parentFilename);
    final URL parentFileURL = parentFileURI.toURL();

    final String childFilename = "child.cmdi";
    final File childFile = new File("/workspaces/" + workspaceID + "/upload/"
            + FilenameUtils.getBaseName(parentFilename) + File.separator + childFilename);
    final URI childFileURI = childFile.toURI();
    final URL childFileURL = childFileURI.toURL();

    final Collection<WorkspaceNode> nodesToCheck = new ArrayList<>();
    nodesToCheck.add(mockChildNode);//from w  ww  . j  a  v a2 s. c o m
    nodesToCheck.add(mockParentNode);

    final Collection<ImportProblem> failedLinks = new ArrayList<>();
    failedLinks.add(mockUploadProblem);
    final Map<MetadataDocument, WorkspaceNode> documentsWithInvalidSelfHandles = new HashMap<>();

    context.checking(new Expectations() {
        {

            // loop

            // first iteration - metadata, so continues in this iteration
            oneOf(mockNodeUtil).isNodeMetadata(mockChildNode);
            will(returnValue(Boolean.TRUE));
            oneOf(mockChildNode).getWorkspaceURL();
            will(returnValue(childFileURL));
            oneOf(mockMetadataAPI).getMetadataDocument(childFileURL);
            will(returnValue(mockChildDocument));

            // second iteration - metadata, so continues in this iteration
            oneOf(mockNodeUtil).isNodeMetadata(mockParentNode);
            will(returnValue(Boolean.TRUE));
            oneOf(mockParentNode).getWorkspaceURL();
            will(returnValue(parentFileURL));
            oneOf(mockMetadataAPI).getMetadataDocument(parentFileURL);
            will(returnValue(mockParentDocument));

            oneOf(mockWorkspaceUploadReferenceHandler).matchReferencesWithNodes(mockWorkpace, nodesToCheck,
                    mockParentNode, mockParentDocument, documentsWithInvalidSelfHandles);
            will(returnValue(failedLinks));
        }
    });

    Collection<ImportProblem> result = workspaceUploadHelper.assureLinksInWorkspace(mockWorkpace, nodesToCheck);

    assertTrue("Result different from expected", result.containsAll(failedLinks));
}

From source file:com.jayway.jsonpath.Criteria.java

boolean singleObjectApply(Map<String, Object> map) {

    for (CriteriaType key : this.criteria.keySet()) {

        Object actualVal = map.get(this.key);
        Object expectedVal = this.criteria.get(key);

        if (CriteriaType.GT.equals(key)) {

            if (expectedVal == null || actualVal == null) {
                return false;
            }/*from ww w  .  j a va 2 s  .  c o m*/

            Number expectedNumber = (Number) expectedVal;
            Number actualNumber = (Number) actualVal;

            return (actualNumber.doubleValue() > expectedNumber.doubleValue());

        } else if (CriteriaType.GTE.equals(key)) {

            if (expectedVal == null || actualVal == null) {
                return false;
            }

            Number expectedNumber = (Number) expectedVal;
            Number actualNumber = (Number) actualVal;

            return (actualNumber.doubleValue() >= expectedNumber.doubleValue());

        } else if (CriteriaType.LT.equals(key)) {

            if (expectedVal == null || actualVal == null) {
                return false;
            }

            Number expectedNumber = (Number) expectedVal;
            Number actualNumber = (Number) actualVal;

            return (actualNumber.doubleValue() < expectedNumber.doubleValue());

        } else if (CriteriaType.LTE.equals(key)) {

            if (expectedVal == null || actualVal == null) {
                return false;
            }

            Number expectedNumber = (Number) expectedVal;
            Number actualNumber = (Number) actualVal;

            return (actualNumber.doubleValue() <= expectedNumber.doubleValue());

        } else if (CriteriaType.NE.equals(key)) {
            if (expectedVal == null && actualVal == null) {
                return false;
            }
            if (expectedVal == null) {
                return true;
            } else {
                return !expectedVal.equals(actualVal);
            }

        } else if (CriteriaType.IN.equals(key)) {

            Collection exp = (Collection) expectedVal;

            return exp.contains(actualVal);

        } else if (CriteriaType.NIN.equals(key)) {

            Collection exp = (Collection) expectedVal;

            return !exp.contains(actualVal);
        } else if (CriteriaType.ALL.equals(key)) {

            Collection exp = (Collection) expectedVal;
            Collection act = (Collection) actualVal;

            return act.containsAll(exp);

        } else if (CriteriaType.SIZE.equals(key)) {

            int exp = (Integer) expectedVal;
            List act = (List) actualVal;

            return (act.size() == exp);

        } else if (CriteriaType.EXISTS.equals(key)) {

            boolean exp = (Boolean) expectedVal;
            boolean act = map.containsKey(this.key);

            return act == exp;

        } else if (CriteriaType.TYPE.equals(key)) {

            Class<?> exp = (Class<?>) expectedVal;
            Class<?> act = null;
            if (map.containsKey(this.key)) {
                Object actVal = map.get(this.key);
                if (actVal != null) {
                    act = actVal.getClass();
                }
            }
            if (act == null) {
                return false;
            } else {
                return act.equals(exp);
            }

        } else if (CriteriaType.REGEX.equals(key)) {

            Pattern exp = (Pattern) expectedVal;
            String act = (String) actualVal;
            if (act == null) {
                return false;
            }
            return exp.matcher(act).matches();

        } else {
            throw new UnsupportedOperationException("Criteria type not supported: " + key.name());
        }
    }
    if (isValue != NOT_SET) {

        if (isValue instanceof Collection) {
            Collection<Criteria> cs = (Collection<Criteria>) isValue;
            for (Criteria crit : cs) {
                for (Criteria c : crit.criteriaChain) {
                    if (!c.singleObjectApply(map)) {
                        return false;
                    }
                }
            }
            return true;
        } else {
            if (isValue == null) {
                return (map.get(key) == null);
            } else {
                return isValue.equals(map.get(key));
            }
        }
    } else {

    }
    return true;
}

From source file:nl.mpi.lamus.workspace.upload.implementation.LamusWorkspaceUploadHelperTest.java

@Test
public void assureLinksPidMetadataReference_ExternalSelfHandle() throws URISyntaxException,
        MalformedURLException, IOException, MetadataException, WorkspaceException, TransformerException {

    final String parentFilename = "parent.cmdi";
    final URI parentFileURI = new URI("file:/workspaces/" + workspaceID + "/upload/" + parentFilename);
    final URL parentFileURL = parentFileURI.toURL();

    final String childFilename = "child.cmdi";
    final File childFile = new File("/workspaces/" + workspaceID + "/upload/"
            + FilenameUtils.getBaseName(parentFilename) + File.separator + childFilename);
    final URI childFileURI = childFile.toURI();
    final URL childFileURL = childFileURI.toURL();

    final Collection<WorkspaceNode> nodesToCheck = new ArrayList<>();
    nodesToCheck.add(mockChildNode);/*from w  ww. j ava2  s  . co m*/
    nodesToCheck.add(mockParentNode);

    final Collection<ImportProblem> failedLinks = new ArrayList<>();
    failedLinks.add(mockUploadProblem);
    final Map<MetadataDocument, WorkspaceNode> documentsWithInvalidSelfHandles = new HashMap<>();

    context.checking(new Expectations() {
        {

            // loop

            // first iteration - metadata, so continues in this iteration
            oneOf(mockNodeUtil).isNodeMetadata(mockChildNode);
            will(returnValue(Boolean.TRUE));
            oneOf(mockChildNode).getWorkspaceURL();
            will(returnValue(childFileURL));
            oneOf(mockMetadataAPI).getMetadataDocument(childFileURL);
            will(returnValue(mockChildDocument));

            // second iteration - metadata, so continues in this iteration
            oneOf(mockNodeUtil).isNodeMetadata(mockParentNode);
            will(returnValue(Boolean.TRUE));
            oneOf(mockParentNode).getWorkspaceURL();
            will(returnValue(parentFileURL));
            oneOf(mockMetadataAPI).getMetadataDocument(parentFileURL);
            will(returnValue(mockParentDocument));

            oneOf(mockWorkspaceUploadReferenceHandler).matchReferencesWithNodes(mockWorkpace, nodesToCheck,
                    mockParentNode, mockParentDocument, documentsWithInvalidSelfHandles);
            will(doAll(AddEntryToMap.putElements(mockParentDocument, mockParentNode),
                    returnValue(failedLinks)));
        }
    });

    context.checking(new Expectations() {
        {
            oneOf(mockParentNode).getWorkspaceURL();
            will(returnValue(parentFileURL));
            oneOf(mockMetadataApiBridge).removeSelfHandleAndSaveDocument(mockParentDocument, parentFileURL);
        }
    });

    Collection<ImportProblem> result = workspaceUploadHelper.assureLinksInWorkspace(mockWorkpace, nodesToCheck);

    assertTrue("Result different from expected", result.containsAll(failedLinks));
}

From source file:at.ac.tuwien.infosys.jcloudscale.test.unit.TestReflectionUtil.java

@Test
public void testGetNamesFromClasses() throws ClassNotFoundException {
    Set<Class<?>> types = new HashSet<>(Primitives.allPrimitiveTypes());
    types.addAll(Primitives.allWrapperTypes());
    Collection<String> typeNames = transform(types, new Function<Class<?>, String>() {
        @Override/* w ww.ja v a  2  s  .c om*/
        public String apply(Class<?> input) {
            return input.getName();
        }
    });

    List<String> names = Arrays.asList(getNamesFromClasses(types.toArray(new Class<?>[types.size()])));
    assertEquals(types.size(), names.size());
    assertEquals(true, typeNames.containsAll(names));
}

From source file:org.intermine.pathquery.LogicExpression.java

/**
 * Takes a List of collections of String variables and returns a List of the same length,
 * containing sections of the LogicExpression with those variables in.
 *
 * @param variables a List of Collections of String variable names
 * @return a List of LogicExpression objects
 * @throws IllegalArgumentException if the LogicExpression cannot be split up in this way,
 * or if there is an overlap in variables, or if there is an unrepresented variable, or if
 * there is an extra variable/* ww w.j a  v a  2 s.  co m*/
 */
public List<LogicExpression> split(List<? extends Collection<String>> variables) {
    Set<String> presentVariables = new HashSet<String>();
    for (Collection<String> v : variables) {
        for (String var : v) {
            if (presentVariables.contains(var)) {
                throw new IllegalArgumentException("There is an overlap in variables");
            }
            presentVariables.add(var);
        }
    }
    if (!presentVariables.equals(getVariableNames())) {
        throw new IllegalArgumentException("Variables in argument (" + presentVariables
                + ") do not match variables in expression (" + getVariableNames() + ")");
    }
    if (root instanceof Variable) {
        return Collections.singletonList(this);
    } else if (root instanceof Or) {
        if (variables.size() == 1) {
            return Collections.singletonList(this);
        } else {
            throw new IllegalArgumentException("Cannot split OR constraint " + toString());
        }
    } else {
        And and = (And) root;
        List<List<String>> buckets = new ArrayList<List<String>>();
        for (int i = 0; i < variables.size(); i++) {
            buckets.add(new ArrayList<String>());
        }
        for (Node node : and.getChildren()) {
            Set<String> hasVariables = new HashSet<String>();
            getVariableNames(hasVariables, node);
            int bucketNo = -1;
            for (int i = 0; i < variables.size(); i++) {
                Collection<String> bucketVariables = variables.get(i);
                if (bucketVariables.containsAll(hasVariables)) {
                    buckets.get(i).add(node.toString());
                    bucketNo = i;
                    break;
                }
            }
            if (bucketNo == -1) {
                throw new IllegalArgumentException("Cannot split node " + node.toString());
            }
        }
        List<LogicExpression> retval = new ArrayList<LogicExpression>();
        for (List<String> bucket : buckets) {
            if (bucket.isEmpty()) {
                retval.add(null);
            } else {
                StringBuffer newExpression = new StringBuffer();
                boolean needComma = false;
                for (String part : bucket) {
                    if (needComma) {
                        newExpression.append(" and ");
                    }
                    needComma = true;
                    newExpression.append("(" + part + ")");
                }
                retval.add(new LogicExpression(newExpression.toString()));
            }
        }
        return retval;
    }
}