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:hudson.plugins.sonar.utils.PathResolverOperatorTest.java

@Test
public void testMergeInternalProperty() {
    final String mergedSetKey = "mergedSet";
    Map<String, Set<String>> sampleData = Maps.newHashMap();
    sampleData.put("includeSet", Sets.newHashSet("value1", "value2"));
    sampleData.put("excludeSet", Sets.newHashSet("value2", "value3"));

    sampleData.put(mergedSetKey, Sets.newHashSet("value3", "value4"));

    Map<String, Set<String>> result = resolverOperator.mergeInternalProperty(sampleData, mergedSetKey,
            "includeSet", "excludeSet");
    assertNotNull(result);// w  w w.j a  v  a 2s  .co m
    assertEquals(1, result.size());
    Set<String> resultSet = result.get(mergedSetKey);
    assertNotNull(resultSet);

    assertEquals(2, resultSet.size());
    assertTrue(resultSet.containsAll(Sets.newHashSet("value1", "value4")));
}

From source file:org.trnltk.morphology.morphotactics.suffixformspecifications.HasLexemeAttributes.java

@Override
public boolean isSatisfiedBy(MorphemeContainer morphemeContainer) {
    Validate.notNull(morphemeContainer);

    Collection<SuffixTransition> suffixTransitions = morphemeContainer.getSuffixTransitions();

    // filter out free suffixTransitions, zero suffixTransitions and suffixTransitions with empty suffix forms
    // since all those three don't change the phonetic attributes of a string
    suffixTransitions = Collections2.filter(suffixTransitions, new Predicate<SuffixTransition>() {
        @Override// ww  w  .j a  va2 s .c o m
        public boolean apply(SuffixTransition input) {
            return !(input.getSuffixFormApplication().getSuffixForm()
                    .getSuffix() instanceof FreeTransitionSuffix)
                    && !(input.getSuffixFormApplication().getSuffixForm()
                            .getSuffix() instanceof ZeroTransitionSuffix)
                    && !(input.getSuffixFormApplication().getSuffixForm()
                            .getSuffix() instanceof ConditionalFreeTransitionSuffix)
                    && StringUtils.isNotEmpty(input.getSuffixFormApplication().getActualSuffixForm()); // The str " " would change the phonetics!
        }
    });

    if (CollectionUtils.isNotEmpty(suffixTransitions))
        return true;

    final Set<LexemeAttribute> morphemeContainerLexemeAttributes = morphemeContainer.getRoot().getLexeme()
            .getAttributes();
    if (CollectionUtils.isEmpty(morphemeContainerLexemeAttributes))
        return false;

    return morphemeContainerLexemeAttributes.containsAll(this.lexemeAttributes);
}

From source file:com.cybernostics.jsp2thymeleaf.api.util.AlternateFormatStrings.java

private String format(Map<String, Object> values) {
    StringBuilder builder = new StringBuilder();
    CandidateFormat formatForValues = formatWhichUsesValues(values).orElseThrow(err(values));
    Set<String> keySet = values.keySet();
    return formatForValues.getParts().stream()
            .filter(p -> p.isRequired() || keySet.containsAll(p.getRequiredAttributes()))
            .map(p -> SimpleStringTemplateProcessor.generate(p.getPart(), values)).collect(joining(""));
}

From source file:com.univocity.app.DataUpdateTest.java

private void executeAndValidate(String entityName, boolean inserting, RowDataCollector dataCollector) {
    System.gc();/*from w  w  w . ja  v  a2s.  c  om*/
    loadProcess.execute(entityName);

    Set<String> persistedRows = dataCollector.getPersistedData();
    Set<String> expectedRows = dataCollector.getExpected();

    if (!expectedRows.containsAll(persistedRows)) {
        @SuppressWarnings("unchecked")
        Collection<String> intersection = CollectionUtils.intersection(persistedRows, expectedRows);

        persistedRows.removeAll(intersection);
        expectedRows.removeAll(intersection);

        if (!isExpectedDiscrepancy(entityName, dataCollector.getFieldNames(), inserting, persistedRows)) {
            fail("Unexpected rows persisted:\n" + persistedRows.size()
                    + "\n\nRows expected but not persisted:\n" + expectedRows.size());
        }
    }
    System.gc();
}

From source file:org.camelcookbook.splitjoin.splitreaggregate.SplitReaggregateSpringTest.java

private void assertBooksByCategory(Exchange exchange) {
    Message in = exchange.getIn();// w  w w.j  av a2 s. c o  m
    @SuppressWarnings("unchecked")
    Set<String> books = Collections.checkedSet(in.getBody(Set.class), String.class);
    String category = in.getHeader("category", String.class);
    switch (category) {
    case "Tech":
        assertTrue(books.containsAll(Collections.singletonList("Apache Camel Developer's Cookbook")));
        break;
    case "Cooking":
        assertTrue(books.containsAll(
                Arrays.asList("Camel Cookbook", "Double decadence with extra cream", "Cooking with Butter")));
        break;
    default:
        fail();
        break;
    }
}

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

private void runOnPair(ProhibitedCompoundRuleEvaluator evaluator, String line, int lineCount, int totalLines,
        String part1, String part2) throws IOException {
    if (finishedPairs.contains(part1 + "/" + part2) || finishedPairs.contains(part2 + "/" + part1)) {
        System.out.println("Ignoring: " + part1 + "/" + part2 + ", finished before");
        return;//from w w w .ja va2  s.com
    }
    for (Map.Entry<String, List<ConfusionPair>> entry : knownSets.entrySet()) {
        if (entry.getKey().equals(part1)) {
            List<ConfusionPair> confusionPair = entry.getValue();
            for (ConfusionPair pair : confusionPair) {
                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:org.springframework.ide.eclipse.boot.wizard.DefaultDependencies.java

/**
 * Stores currently selection dependencies as default dependencies 
 * /*  ww w .  j av a2 s.com*/
 * @param model dependency selection model
 * @return <code>true</code> if dependencies were stored, i.e. currently stored are different from the current ones. 
 */
public boolean save(HierarchicalMultiSelectionFieldModel<Dependency> model) {
    Set<String> ids = getDependciesIdSet();
    String[] currentSelection = model.getCurrentSelection().stream().map(Dependency::getId)
            .toArray(String[]::new);
    if (ids.size() == currentSelection.length && ids.containsAll(Arrays.asList(currentSelection))) {
        // Nothing to store no changes detected
        return false;
    } else {
        // Store dependencies ids as current selection has differences from currently stored dependencies
        put(PREF_DEFAULT_DEPENDENCIES, String.join(DEPENDECIES_DELIMITER, currentSelection));
        return true;
    }
}

From source file:org.apache.samza.system.hdfs.partitioner.DirectoryPartitioner.java

private List<FileMetadata> validateAndGetOriginalFilteredFiles(List<FileMetadata> newFileList,
        Map<Partition, List<String>> existingPartitionDescriptor) {
    assert newFileList != null;
    assert existingPartitionDescriptor != null;
    Set<String> oldFileSet = new HashSet<>();
    existingPartitionDescriptor.values().forEach(oldFileSet::addAll);
    Set<String> newFileSet = new HashSet<>();
    newFileList.forEach(file -> newFileSet.add(file.getPath()));
    if (!newFileSet.containsAll(oldFileSet)) {
        throw new SamzaException("The list of new files is not a super set of the old files. diff = "
                + oldFileSet.removeAll(newFileSet));
    }/*w ww  .  j  ava2 s .  c o  m*/
    Iterator<FileMetadata> iterator = newFileList.iterator();
    while (iterator.hasNext()) {
        FileMetadata file = iterator.next();
        if (!oldFileSet.contains(file.getPath())) {
            iterator.remove();
        }
    }
    return newFileList;
}

From source file:de.pixida.logtest.buildserver.RunIntegrationTestsTest.java

@Test
public void testInputFilesAreFound() {
    final String automatonsPath = this.getTestScenarioPath("test-scenario/automatons");
    final String tracesPath = this.getTestScenarioPath("test-scenario/traces");
    final RunIntegrationTests r = new RunIntegrationTests();
    r.parseCommandLine(new String[] { "-a", automatonsPath, "-t", tracesPath,
            "trace0-success.txt:test-no-bluescreen-appeared.json" });
    final Map<File, List<Pair<File, Map<String, String>>>> executions = r.getConfiguredExecutions();
    final Set<File> expectedTraces = new HashSet<>(Arrays.asList(new File(tracesPath, "trace0-success.txt")));
    Assert.assertTrue(/* w  w  w .j  ava2 s . c  o m*/
            expectedTraces.containsAll(executions.keySet()) && executions.keySet().containsAll(expectedTraces));
    Assert.assertEquals(new File(automatonsPath, "test-no-bluescreen-appeared.json"),
            executions.get(expectedTraces.iterator().next()).get(0).getLeft());
    Assert.assertEquals(0, executions.get(expectedTraces.iterator().next()).get(0).getRight().size());
}

From source file:org.apache.accumulo.core.iterators.system.LocalityGroupIterator.java

public static final int seek(HeapIterator hiter, LocalityGroup[] groups,
        Set<ByteSequence> nonDefaultColumnFamilies, Range range, Collection<ByteSequence> columnFamilies,
        boolean inclusive) throws IOException {
    hiter.clear();/*from   w w w.j ava 2 s  . com*/

    int numLGSeeked = 0;

    Set<ByteSequence> cfSet;
    if (columnFamilies.size() > 0)
        if (columnFamilies instanceof Set<?>) {
            cfSet = (Set<ByteSequence>) columnFamilies;
        } else {
            cfSet = new HashSet<ByteSequence>();
            cfSet.addAll(columnFamilies);
        }
    else
        cfSet = Collections.emptySet();

    for (LocalityGroup lgr : groups) {
        // when include is set to true it means this locality groups contains
        // wanted column families
        boolean include = false;

        if (cfSet.size() == 0) {
            include = !inclusive;
        } else if (lgr.isDefaultLocalityGroup && lgr.columnFamilies == null) {
            // do not know what column families are in the default locality group,
            // only know what column families are not in it

            if (inclusive) {
                if (!nonDefaultColumnFamilies.containsAll(cfSet)) {
                    // default LG may contain wanted and unwanted column families
                    include = true;
                } // else - everything wanted is in other locality groups, so nothing to do
            } else {
                // must include, if all excluded column families are in other locality groups
                // then there are not unwanted column families in default LG
                include = true;
            }
        } else {
            /*
             * Need to consider the following cases for inclusive and exclusive (lgcf:locality group column family set, cf:column family set) lgcf and cf are
             * disjoint lgcf and cf are the same cf contains lgcf lgcf contains cf lgccf and cf intersect but neither is a subset of the other
             */

            for (Entry<ByteSequence, MutableLong> entry : lgr.columnFamilies.entrySet())
                if (entry.getValue().longValue() > 0)
                    if (cfSet.contains(entry.getKey())) {
                        if (inclusive)
                            include = true;
                    } else if (!inclusive) {
                        include = true;
                    }
        }

        if (include) {
            lgr.getIterator().seek(range, EMPTY_CF_SET, false);
            hiter.addSource(lgr.getIterator());
            numLGSeeked++;
        } // every column family is excluded, zero count, or not present
    }

    return numLGSeeked;
}