Example usage for java.util List containsAll

List of usage examples for java.util List containsAll

Introduction

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

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

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

Usage

From source file:org.apache.falcon.resource.metadata.LineageMetadataResourceTest.java

private void verifyVertexEdges(String vertexId, String direction, int expectedSize, List<String> expected) {
    LineageMetadataResource resource = new LineageMetadataResource();
    Response response = resource.getVertexEdges(vertexId, direction);
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());

    Map results = (Map) JSONValue.parse(response.getEntity().toString());
    long totalSize = Long.valueOf(results.get(LineageMetadataResource.TOTAL_SIZE).toString());
    Assert.assertEquals(totalSize, expectedSize);

    ArrayList propertyList = (ArrayList) results.get(LineageMetadataResource.RESULTS);
    List<String> actual = new ArrayList<String>();
    for (Object property : propertyList) {
        actual.add((String) ((Map) property).get(RelationshipProperty.NAME.getName()));
    }//  w  w  w.  j a v  a2 s  . com

    Assert.assertTrue(actual.containsAll(expected));
}

From source file:org.glite.slcs.acl.impl.XMLFileAccessControlList.java

public boolean isAuthorized(List userAttributes) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("userAttributes=" + userAttributes);
    }//from   ww  w .  j a v  a2  s.c o m
    boolean authorized = false;
    Iterator rules = accessControlRules_.iterator();
    while (!authorized && rules.hasNext()) {
        AccessControlRule rule = (AccessControlRule) rules.next();
        List ruleAttributes = rule.getAttributes();
        if (LOG.isDebugEnabled()) {
            LOG.debug("checking rule:" + rule);
        }
        // only rule attrs know if they are caseSensitive or not...
        if (userAttributes.containsAll(ruleAttributes)) {
            authorized = true;
            LOG.info("User authorized by rule: " + rule);
        }
    }

    if (!authorized) {
        LOG.warn("User not authorized: " + userAttributes);
    }

    return authorized;
}

From source file:uk.ac.ebi.phenotype.service.HpOntologyServiceTest.java

/**
 * Test of getSynonyms method, of class MpOntologyService.
 * /*from w  ww.  ja va 2 s .c o  m*/
 * @throws SQLException
 */
//@Ignore
@Test
public void testGetSynonyms3Synonyms() throws SQLException {
    System.out.println("testGetSynonyms3Synonyms");
    String[] expectedSynonymsArray = new String[] { "Absent kidney", "Renal aplasia" };
    List<String> actualSynonyms = instance.getSynonyms("HP:0000104");

    List<String> expectedSynonyms = Arrays.asList(expectedSynonymsArray);

    String errMsg = "Expected at least 2 synonyms. Actual # synonyms = " + actualSynonyms.size() + ".";
    assertTrue(errMsg, actualSynonyms.size() >= 2);

    if (!actualSynonyms.containsAll(expectedSynonyms)) {
        fail("Expected synonyms " + expectedSynonyms + ". Actual synonyms = "
                + StringUtils.join(actualSynonyms, ", "));
    }
}

From source file:org.spring.data.gemfire.cache.RepositoryQueriesWithJoinsTest.java

@Test
public void testJoinQueries() {
    Customer jonDoe = customerRepo.save(createCustomer("Jon", "Doe"));
    Customer janeDoe = customerRepo.save(createCustomer("Jane", "Doe"));
    Customer jackHandy = customerRepo.save(createCustomer("Jack", "Handy"));

    Account jonAccountOne = accountRepo.save(createAccount(jonDoe, "1"));
    Account jonAccountTwo = accountRepo.save(createAccount(jonDoe, "2"));
    Account janeAccount = accountRepo.save(createAccount(janeDoe, "1"));

    List<Customer> actualCustomersWithAccounts = customerRepo.findCustomersWithAccounts();
    List<Customer> expectedCustomersWithAccounts = Arrays.asList(jonDoe, janeDoe);

    assertNotNull(actualCustomersWithAccounts);
    assertFalse(String.format("Expected Customers (%1$s)!", expectedCustomersWithAccounts),
            actualCustomersWithAccounts.isEmpty());
    assertEquals(String.format("Expected Customers (%1$s); but was (%2$s)!", expectedCustomersWithAccounts,
            actualCustomersWithAccounts), 2, actualCustomersWithAccounts.size());
    assertTrue(//from ww w  .j  av a2s . c o  m
            String.format("Expected Customers (%1$s); but was (%2$s)!", expectedCustomersWithAccounts,
                    actualCustomersWithAccounts),
            actualCustomersWithAccounts.containsAll(expectedCustomersWithAccounts));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void findsAllMusicians() throws Exception {
    List<Person> result = repository.findAll();
    assertThat(result.size(), is(all.size()));
    assertThat(result.containsAll(all), is(true));
}

From source file:com.linkedin.pinot.controller.helix.core.rebalance.DefaultRebalanceStrategyTest.java

private void validateIdealState(IdealState rebalancedIdealState, int nSegments, int targetNumReplicas,
        List<String> instances, Map<String, Map<String, String>> prevAssignment, boolean changeExpected) {
    Assert.assertEquals(rebalancedIdealState.getPartitionSet().size(), nSegments);
    for (String segment : rebalancedIdealState.getPartitionSet()) {
        Map<String, String> instanceStateMap = rebalancedIdealState.getInstanceStateMap(segment);
        Assert.assertEquals(instanceStateMap.size(), targetNumReplicas);
        Assert.assertTrue(instances.containsAll(instanceStateMap.keySet()));
    }//  w  w  w . j  a  v a2  s.  c  om

    boolean changed = false;
    for (String segment : prevAssignment.keySet()) {
        Map<String, String> prevInstanceMap = prevAssignment.get(segment);
        Map<String, String> instanceStateMap = rebalancedIdealState.getInstanceStateMap(segment);
        if (!changeExpected) {
            Assert.assertTrue(prevInstanceMap.keySet().containsAll(instanceStateMap.keySet()));
            Assert.assertTrue(instanceStateMap.keySet().containsAll(prevInstanceMap.keySet()));
        } else {
            if (!prevInstanceMap.keySet().containsAll(instanceStateMap.keySet())
                    || !instanceStateMap.keySet().containsAll(prevInstanceMap.keySet())) {
                changed = true;
                break;
            }
        }
    }
    Assert.assertEquals(changeExpected, changed);
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java

private static Pair<Boolean, Boolean> pushThroughOp(HashSet<LogicalVariable> toPush,
        Mutable<ILogicalOperator> opRef2, ILogicalOperator initialOp, IOptimizationContext context)
        throws AlgebricksException {
    List<LogicalVariable> initProjectList = new ArrayList<LogicalVariable>(toPush);
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
    do {/*from   w  w w .j a  v  a  2s . com*/
        if (op2.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE
                || op2.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE
                || op2.getOperatorTag() == LogicalOperatorTag.PROJECT
                || op2.getOperatorTag() == LogicalOperatorTag.REPLICATE
                || op2.getOperatorTag() == LogicalOperatorTag.UNIONALL) {
            return new Pair<Boolean, Boolean>(false, false);
        }
        if (!op2.isMap()) {
            break;
        }
        LinkedList<LogicalVariable> usedVars = new LinkedList<LogicalVariable>();
        VariableUtilities.getUsedVariables(op2, usedVars);
        toPush.addAll(usedVars);
        LinkedList<LogicalVariable> producedVars = new LinkedList<LogicalVariable>();
        VariableUtilities.getProducedVariables(op2, producedVars);
        toPush.removeAll(producedVars);
        // we assume pipelineable ops. have only one input
        opRef2 = op2.getInputs().get(0);
        op2 = (AbstractLogicalOperator) opRef2.getValue();
    } while (true);

    LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>();
    VariableUtilities.getProducedVariables(op2, produced2);
    LinkedList<LogicalVariable> used2 = new LinkedList<LogicalVariable>();
    VariableUtilities.getUsedVariables(op2, used2);

    boolean canCommuteProjection = initProjectList.containsAll(toPush) && initProjectList.containsAll(produced2)
            && initProjectList.containsAll(used2);
    // if true, we can get rid of the initial projection

    // get rid of useless decor vars.
    if (!canCommuteProjection && op2.getOperatorTag() == LogicalOperatorTag.GROUP) {
        boolean gbyChanged = false;
        GroupByOperator gby = (GroupByOperator) op2;
        List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> newDecorList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getDecorList()) {
            LogicalVariable decorVar = GroupByOperator.getDecorVariable(p);
            if (!toPush.contains(decorVar)) {
                used2.remove(decorVar);
                gbyChanged = true;
            } else {
                newDecorList.add(p);
            }
        }
        gby.getDecorList().clear();
        gby.getDecorList().addAll(newDecorList);
        if (gbyChanged) {
            context.computeAndSetTypeEnvironmentForOperator(gby);
        }
    }
    used2.clear();
    VariableUtilities.getUsedVariables(op2, used2);

    toPush.addAll(used2); // remember that toPush is a Set
    toPush.removeAll(produced2);

    if (toPush.isEmpty()) {
        return new Pair<Boolean, Boolean>(false, false);
    }

    boolean smthWasPushed = false;
    for (Mutable<ILogicalOperator> c : op2.getInputs()) {
        if (pushNeededProjections(toPush, c, context, initialOp)) {
            smthWasPushed = true;
        }
    }
    if (op2.hasNestedPlans()) {
        AbstractOperatorWithNestedPlans n = (AbstractOperatorWithNestedPlans) op2;
        for (ILogicalPlan p : n.getNestedPlans()) {
            for (Mutable<ILogicalOperator> r : p.getRoots()) {
                if (pushNeededProjections(toPush, r, context, initialOp)) {
                    smthWasPushed = true;
                }
            }
        }
    }
    return new Pair<Boolean, Boolean>(smthWasPushed, canCommuteProjection);
}

From source file:com.facebook.samples.booleanog.LogicActivity.java

private void sendPendingPost() {
    if (pendingPost == null) {
        return;//from w w  w .  j  a  v  a 2  s  . c  o  m
    }

    Session session = Session.getActiveSession();
    if ((session == null) || !session.isOpened()) {
        postResultText.setText("Not logged in, no post generated.");
        pendingPost = null;
        return;
    }

    List<String> permissions = session.getPermissions();
    if (!permissions.containsAll(PERMISSIONS)) {
        Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this,
                PERMISSIONS);
        session.requestNewPublishPermissions(newPermissionsRequest);
        return;
    }

    postResultText.setText("Posting action...");

    // For demo purposes, result is just a boolean, but operands are Open Graph objects
    String actionPath = pendingPost.getString(PENDING_POST_PATH);
    boolean leftOperand = pendingPost.getBoolean(PENDING_POST_LEFT);
    boolean rightOperand = pendingPost.getBoolean(PENDING_POST_RIGHT);
    boolean result = pendingPost.getBoolean(PENDING_POST_RESULT);

    LogicAction action = GraphObject.Factory.create(LogicAction.class);
    action.setResult(result);
    action.setTruthvalue(getTruthValueObject(leftOperand));
    action.setAnothertruthvalue(getTruthValueObject(rightOperand));

    Request.Callback callback = new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
            onPostActionResponse(response);
        }
    };
    Request request = new Request(session, actionPath, null, HttpMethod.POST, callback);
    request.setGraphObject(action);
    RequestAsyncTask task = new RequestAsyncTask(request);

    task.execute();
}

From source file:org.fao.geonet.api.users.UsersApi.java

@ApiOperation(value = "Get users", notes = "", nickname = "getUsers")
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)/*from www . ja  v a 2 s.co  m*/
@PreAuthorize("isAuthenticated()")
@ResponseBody
public List<User> getUsers(@ApiIgnore HttpSession httpSession) throws Exception {
    UserSession session = ApiUtils.getUserSession(httpSession);
    Profile profile = session.getProfile();

    UserRepository userRepository = ApplicationContextHolder.get().getBean(UserRepository.class);

    if (profile == Profile.Administrator) {
        return userRepository.findAll(SortUtils.createSort(User_.name));
    } else if (profile != Profile.UserAdmin) {
        return userRepository.findAll(UserSpecs.hasUserId(session.getUserIdAsInt()));
    } else if (profile == Profile.UserAdmin) {
        int userId = session.getUserIdAsInt();
        final List<Integer> userGroupIds = getGroupIds(userId);

        List<User> allUsers = userRepository.findAll(SortUtils.createSort(User_.name));

        // Filter users which are not in current user admin groups
        allUsers.removeIf(u -> !userGroupIds.containsAll(getGroupIds(u.getId()))
                || u.getProfile().equals(Profile.Administrator));
        //              TODO-API: Check why there was this check on profiles ?
        //                    if (!profileSet.contains(profile))
        //                        alToRemove.add(elRec);

        return allUsers;
    }

    return null;
}

From source file:org.apache.falcon.regression.entity.EntitiesPatternSearchTest.java

private void validateOutputPatternList(EntityElement[] entityElements, EntityElement[] outputelements,
        String pattern) {/*from www . j  a  v  a  2s  .  c o  m*/
    List<String> actualOutputElements = new ArrayList<>();
    List<String> expectedOutputElements = new ArrayList<>();
    for (EntityElement e : entityElements) {
        if (getOutputEntity(e.name, pattern)) {
            expectedOutputElements.add(e.name);
        }
    }

    for (EntityElement e : outputelements) {
        actualOutputElements.add(e.name);
    }

    LOGGER.debug("actualElement : " + actualOutputElements);
    LOGGER.debug("expectedElement : " + expectedOutputElements);

    // Checking no of elements present in output.
    AssertUtil.checkForListSizes(expectedOutputElements, actualOutputElements);

    //Checking expected out and actual output contains same enitities.
    Assert.assertTrue(expectedOutputElements.containsAll(actualOutputElements),
            "Output list elements are not as expected");

    for (String element : expectedOutputElements) {
        Assert.assertTrue(actualOutputElements.contains(element),
                "Element " + element + "is not present in output");
    }
}