Example usage for java.util Set containsAll

List of usage examples for java.util Set containsAll

Introduction

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

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

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

Usage

From source file:rql4j.builder.PageBuilderTest.java

public void testPageBuilderXSearch() throws Exception {
    PageBuilder pageBuilder = new PageBuilder.XSearch().PageSize("-1").OrderBy(Page.OrderBy.CREATEDATE)
            .OrderDirection(Page.OrderDirection.DESC).SearchContentClassGuid(
                    properties.getProperty("cms.test.contentclass.guid"), SearchItem.Operator.EQ)
            .build();/*from w  ww  .ja  v  a  2s  .com*/
    List<Page> pages = command.getResult(pageBuilder).getIoData().getPages().getPageList();
    Set<String> pageGuids = new HashSet<String>();
    for (Page page : pages) {
        pageGuids.add(page.getGuid());
        System.out.println("Headline: " + page.getHeadline() + ", Guid: " + page.getGuid());
    }
    Assert.assertEquals(true, pageGuids.containsAll(this.pageGuids));
}

From source file:org.sakaiproject.adminsiteperms.tool.ActionBean.java

@SuppressWarnings("unchecked")
protected void setSiteRolePerms(boolean add) {
    String permsString = makeStringFromArray(perms);
    String typesString = makeStringFromArray(types);
    String rolesString = makeStringFromArray(roles);
    List<String> permsList = Arrays.asList(perms);
    // now add the perms to all matching roles in all matching sites
    List<Site> sites = siteService.getSites(SelectionType.ANY, types, null, null, SortType.NONE, null);
    int successCount = 0;
    for (Site site : sites) {
        String siteRef = site.getReference();
        try {//from  www .j a va  2s .  co m
            AuthzGroup ag = authzGroupService.getAuthzGroup(siteRef);
            if (authzGroupService.allowUpdate(ag.getId())) {
                boolean updated = false;
                for (String role : roles) {
                    Role r = ag.getRole(role);
                    // if role not found in this group then move on
                    if (r != null) {
                        // get the current perms so we can possibly avoid an update
                        Set<String> current = r.getAllowedFunctions();
                        if (add) {
                            if (!current.containsAll(permsList)) {
                                // only update if the perms are not already there
                                r.allowFunctions(permsList);
                                updated = true;
                            }
                        } else {
                            boolean found = false;
                            for (String perm : permsList) {
                                if (current.contains(perm)) {
                                    found = true;
                                    break;
                                }
                            }
                            if (found) {
                                // only update if at least one perm needs to be removed
                                r.disallowFunctions(permsList);
                                updated = true;
                            }
                        }
                    }
                }
                if (updated) {
                    // only save if the group was updated
                    authzGroupService.save(ag);
                    log.info("Added Permissions (" + permsString + ") for roles (" + rolesString + ") to group:"
                            + siteRef);
                }
                successCount++;
            } else {
                log.warn("Cannot update authz group: " + siteRef + ", unable to apply any perms change");
            }
        } catch (GroupNotDefinedException e) {
            log.error("Could not find authz group: " + siteRef + ", unable to apply any perms change");
        } catch (AuthzPermissionException e) {
            log.error("Could not save authz group: " + siteRef + ", unable to apply any perms change");
        }
    }
    int failureCount = sites.size() - successCount;
    String operation = (add ? "adding" : "removing");
    messages.addMessage(new TargettedMessage("user.message.permissions." + (add ? "added" : "removed"),
            new Object[] { typesString, rolesString, permsString, sites.size(), successCount, failureCount },
            TargettedMessage.SEVERITY_INFO));
    log.info("Completed " + operation + " permissions (" + permsString + ") in " + sites.size()
            + " sites of types (" + typesString + ") for the following roles (" + rolesString + "), "
            + "there were " + successCount + " successful updates and " + failureCount + " failures");
}

From source file:acromusashi.stream.component.rabbitmq.RabbitmqClusterContext.java

/**
 * RabbitMQ?RabbitMQ????????// w ww  .  j a va 2  s.c o  m
 * 
 * @param mqProcessList RabbitMQ
 * @param connectionProcessMap ?RabbitMQ?
 * @throws RabbitmqCommunicateException RabbitMQ?RabbitMQ???????
 */
private void validateProcessReference(List<String> mqProcessList, Map<String, String> connectionProcessMap)
        throws RabbitmqCommunicateException {
    //RabbitMQ?????
    if (mqProcessList == null || mqProcessList.size() == 0) {
        String message = "ProcessList is not defined.";
        throw new RabbitmqCommunicateException(message);
    }

    // ?RabbitMQ?????????
    if (connectionProcessMap == null || connectionProcessMap.size() == 0) {
        return;
    }

    Set<String> processSet = new HashSet<String>(mqProcessList);
    Set<String> connectionProcessSet = new HashSet<String>(connectionProcessMap.values());

    if (processSet.containsAll(connectionProcessSet) == false) {
        @SuppressWarnings("unchecked")
        Set<String> nonContainedProcessSet = new HashSet<String>(
                CollectionUtils.subtract(connectionProcessSet, processSet));
        String messageFmt = "Connection process is illegal. NonContainedProcessSet={0}";
        String message = MessageFormat.format(messageFmt, nonContainedProcessSet.toString());
        throw new RabbitmqCommunicateException(message);
    }
}

From source file:org.languagetool.dev.bigdata.AutomaticConfusionRuleEvaluator.java

private void runOnPair(ConfusionRuleEvaluator evaluator, String line, int lineCount, int totalLines,
        String part1, String part2, boolean bothDirections) throws IOException {
    boolean finishedBefore = bothDirections
            ? finishedPairs.contains(part1 + "/" + part2) || finishedPairs.contains(part2 + "/" + part1)
            : finishedPairs.contains(part1 + "/" + part2);
    if (finishedBefore) {
        System.out.println("Ignoring: " + part1 + "/" + part2 + ", finished before");
        return;/*w w w  .ja v a  2 s  . c o m*/
    }
    for (Map.Entry<String, List<ConfusionPair>> entry : knownSets.entrySet()) {
        if (entry.getKey().equals(part1)) {
            List<ConfusionPair> confusionPairs = entry.getValue();
            for (ConfusionPair pair : confusionPairs) {
                Set<String> stringSet = pair.getTerms().stream().map(l -> l.getString())
                        .collect(Collectors.toSet());
                if (stringSet.containsAll(Arrays.asList(part1, part2))) {
                    System.out
                            .println("Ignoring: " + part1 + "/" + part2 + ", in active confusion sets already");
                    ignored++;
                    return;
                }
            }
        }
    }
    System.out.println("Working on: " + line + " (" + lineCount + " of " + totalLines + ")");
    try {
        File sentencesFile = writeExampleSentencesToTempFile(new String[] { part1, part2 });
        List<String> input = Arrays.asList(sentencesFile.getAbsolutePath());
        Map<Long, RuleEvalResult> results = evaluator.run(input, part1, part2, MAX_EXAMPLES, EVAL_FACTORS);
        Map<Long, RuleEvalResult> bestResults = findBestFactor(results);
        if (bestResults.size() > 0) {
            for (Map.Entry<Long, RuleEvalResult> entry : bestResults.entrySet()) {
                System.out.println("=> " + entry.getValue().getSummary());
            }
        } else {
            System.out.println("No good result found for " + part1 + "/" + part2);
        }
        finishedPairs.add(part1 + "/" + part2);
    } catch (TooFewExamples e) {
        System.out.println("Skipping " + part1 + "/" + part2 + ", too few examples: " + e.getMessage());
    }
}

From source file:ddf.test.itests.platform.TestSolrCommands.java

@Ignore
@Test/*from ww  w  . j av  a  2 s  .  com*/
public void testSolrBackupNumToKeep() throws InterruptedException {
    int numToKeep = 2;

    String command = BACKUP_COMMAND + " --numToKeep " + numToKeep;

    // Run this 3 times to make sure 2 backups are kept
    // On run 1, backup A is created.
    console.runCommand(command);
    Set<File> firstBackupDirSet = waitForBackupDirsToBeCreated(CATALOG_CORE_NAME, 1, 1);

    // On run 2, backup B is created (2 backups now: A and B).
    console.runCommand(command);
    Set<File> secondBackupDirSet = waitForBackupDirsToBeCreated(CATALOG_CORE_NAME, 2, 2);
    assertTrue("Unexpected backup directories found on pass 2.",
            secondBackupDirSet.containsAll(firstBackupDirSet));

    // On run 3, backup C is created (backup A is deleted and backups B and C remain).
    console.runCommand(command);
    // Wait for the 3rd backup to replace the 1st backup
    Set<File> thirdBackupDirSet = waitForFirstBackupDirToBeDeleted(CATALOG_CORE_NAME, firstBackupDirSet);

    assertThat("Wrong number of backup directories kept. Number of backups found in "
            + getSolrDataPath(CATALOG_CORE_NAME).getAbsolutePath() + " is : [" + thirdBackupDirSet.size()
            + "]; Expected: [2].", thirdBackupDirSet, hasSize(2));

    secondBackupDirSet.removeAll(firstBackupDirSet);
    assertTrue("Unexpected backup directories found on pass 3.",
            thirdBackupDirSet.containsAll(secondBackupDirSet));
}

From source file:org.jtalks.poulpe.model.dao.hibernate.ComponentHibernateDaoTest.java

private void assertAllTypesAvailable(Set<ComponentType> availableTypes) {
    List<ComponentType> allActualTypes = Arrays.asList(ComponentType.values());
    assertEquals(availableTypes.size(), allActualTypes.size());
    assertTrue(availableTypes.containsAll(allActualTypes));
}

From source file:com.netflix.conductor.contribs.http.TestHttpTask.java

@SuppressWarnings("unchecked")
@Test//from ww  w.j  a v  a2  s.  c om
public void testPost() throws Exception {

    Task task = new Task();
    Input input = new Input();
    input.setUri("http://localhost:7009/post");
    Map<String, Object> body = new HashMap<>();
    body.put("input_key1", "value1");
    body.put("input_key2", 45.3d);
    input.setBody(body);
    input.setMethod("POST");
    task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);

    httpTask.start(workflow, task, executor);
    assertEquals(task.getReasonForIncompletion(), Task.Status.COMPLETED, task.getStatus());
    HttpResponse hr = (HttpResponse) task.getOutputData().get("response");
    Object response = hr.body;
    assertEquals(Task.Status.COMPLETED, task.getStatus());
    assertTrue("response is: " + response, response instanceof Map);
    Map<String, Object> map = (Map<String, Object>) response;
    Set<String> inputKeys = body.keySet();
    Set<String> responseKeys = map.keySet();
    inputKeys.containsAll(responseKeys);
    responseKeys.containsAll(inputKeys);
}

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

private boolean isIndependentFromChildren(OrderOperator order1) throws AlgebricksException {
    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(order1, free);
    Set<LogicalVariable> usedInOrder = new HashSet<LogicalVariable>();
    VariableUtilities.getUsedVariables(order1, usedInOrder);
    return free.containsAll(usedInOrder);
}

From source file:fi.vm.kapa.identification.proxy.utils.SessionHandlingUtils.java

public boolean authMethodsInPermittedMethods(String authMethods, String permittedMethods) {
    Set<String> requestedMethodSet = new HashSet<String>(Arrays.asList(authMethods.split(";")));
    Set<String> permittedMethodSet = new HashSet<String>(Arrays.asList(permittedMethods.split(";")));

    if (permittedMethodSet.containsAll(requestedMethodSet)) {
        return true;
    }/*from   w  w  w  .  ja  va 2 s  .c o m*/
    return false;
}

From source file:uniol.apt.adt.automaton.FiniteAutomatonUtility.java

/**
 * Get a finite automaton accepting the negation of the language of the given automaton. A word is in the
 * negation of the language if is is not in the language itself.
 * @param a The automaton whose language is to negate.
 * @param alphabet The alphabet of the negation
 * @return An automaton accepting the negation.
 *///from w w  w .java 2s .  c o m
static public DeterministicFiniteAutomaton negate(DeterministicFiniteAutomaton a, Set<Symbol> alphabet) {
    if (!alphabet.containsAll(a.getAlphabet())) {
        throw new IllegalArgumentException("Alphabet of the automaton isn't subset of the given alphabet.");
    }

    return getAutomaton(new NegationState(a.getInitialState(), new HashSet<>(alphabet)));
}