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:MainClass.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new HashSet(Arrays.asList(elements));

    elements = new String[] { "A", "B", "C" };
    Set set2 = new HashSet(Arrays.asList(elements));

    System.out.println(set.containsAll(set2));
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set<String> set = new HashSet<String>(Arrays.asList(elements));

    elements = new String[] { "A", "B", "C" };
    Set<String> set2 = new HashSet<String>(Arrays.asList(elements));

    System.out.println(set.containsAll(set2));
}

From source file:com.act.biointerpretation.l2expansion.L2FilteringDriver.java

public static void main(String[] args) throws Exception {

    // Build command line parser.
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());//from   ww  w . j a va2s.c  o  m
    }

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        LOGGER.error("Argument parsing failed: %s", e.getMessage());
        HELP_FORMATTER.printHelp(L2FilteringDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    // Print help.
    if (cl.hasOption(OPTION_HELP)) {
        HELP_FORMATTER.printHelp(L2FilteringDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        return;
    }

    checkFilterOptionIsValid(OPTION_CHEMICAL_FILTER, cl);
    checkFilterOptionIsValid(OPTION_REACTION_FILTER, cl);

    // Get corpus files.
    File corpusFile = new File(cl.getOptionValue(OPTION_INPUT_CORPUS));
    if (!corpusFile.exists()) {
        LOGGER.error("Input corpus file does not exist.");
        return;
    }

    File outputFile = new File(cl.getOptionValue(OPTION_OUTPUT_PATH));
    outputFile.createNewFile();
    if (outputFile.isDirectory()) {
        LOGGER.error("Output file is directory.");
        System.exit(1);
    }

    LOGGER.info("Reading corpus from file.");
    L2PredictionCorpus predictionCorpus = L2PredictionCorpus.readPredictionsFromJsonFile(corpusFile);
    LOGGER.info("Read in corpus with %d predictions.", predictionCorpus.getCorpus().size());
    LOGGER.info("Corpus has %d distinct substrates.", predictionCorpus.getUniqueSubstrateInchis().size());

    if (cl.hasOption(OPTION_FILTER_SUBSTRATES)) {
        LOGGER.info("Filtering by substrates.");
        File substratesFile = new File(cl.getOptionValue(OPTION_FILTER_SUBSTRATES));
        L2InchiCorpus inchis = new L2InchiCorpus();
        inchis.loadCorpus(substratesFile);
        Set<String> inchiSet = new HashSet<String>();
        inchiSet.addAll(inchis.getInchiList());

        predictionCorpus = predictionCorpus
                .applyFilter(prediction -> inchiSet.containsAll(prediction.getSubstrateInchis()));

        predictionCorpus.writePredictionsToJsonFile(outputFile);
        LOGGER.info("Done writing filtered corpus to file.");
        return;
    }

    if (cl.hasOption(OPTION_SPLIT_BY_RO)) {
        LOGGER.info("Splitting corpus into distinct corpuses for each ro.");
        Map<String, L2PredictionCorpus> corpusMap = predictionCorpus
                .splitCorpus(prediction -> prediction.getProjectorName());

        for (Map.Entry<String, L2PredictionCorpus> entry : corpusMap.entrySet()) {
            String fileName = cl.getOptionValue(OPTION_OUTPUT_PATH) + "." + entry.getKey();
            File oneOutputFile = new File(fileName);
            entry.getValue().writePredictionsToJsonFile(oneOutputFile);
        }
        LOGGER.info("Done writing split corpuses to file.");
        return;
    }

    predictionCorpus = runDbLookups(cl, predictionCorpus, opts);

    LOGGER.info("Applying filters.");
    predictionCorpus = applyFilter(predictionCorpus, ALL_CHEMICALS_IN_DB, cl, OPTION_CHEMICAL_FILTER);
    predictionCorpus = applyFilter(predictionCorpus, REACTION_MATCHES_DB, cl, OPTION_REACTION_FILTER);
    LOGGER.info("Filtered corpus has %d predictions.", predictionCorpus.getCorpus().size());

    LOGGER.info("Printing final corpus.");
    predictionCorpus.writePredictionsToJsonFile(outputFile);

    LOGGER.info("L2FilteringDriver complete!.");
}

From source file:Main.java

public static <T> boolean isSubset(Set<T> setA, Set<T> setB) {
    return setB.containsAll(setA);
}

From source file:Main.java

public static <T> boolean isSuperset(Set<T> setA, Set<T> setB) {
    return setA.containsAll(setB);
}

From source file:Main.java

/**
 * This method returns true if set A is a superset of set B
 * i.e. it answers the question if A contains all items from B
 * @param setA set A/*from   w  ww .j  a va  2 s .com*/
 * @param setB set B
 * @param <T> type
 * @return {@code boolean} true if A is a superset of B
 */
public static <T> boolean isSuperset(Set<T> setA, Set<T> setB) {
    return setA.containsAll(setB);
}

From source file:Main.java

public static void testForSubset(Set<String> s1, Set<String> s2) {
    System.out.println("s2 is  subset s1: " + s1.containsAll(s2));
    System.out.println("s1 is  subset s2: " + s2.containsAll(s1));
}

From source file:com.espertech.esperio.csv.CSVPropertyOrderHelper.java

private static boolean eachPropertyNameRepresented(String[] row, Map<String, Object> propertyTypes) {
    Set<String> rowSet = new HashSet<String>(Arrays.asList(row));
    return rowSet.containsAll(propertyTypes.keySet());
}

From source file:Main.java

/**
 * Test whether col2 is contained in col1.
 * /*  w w  w  .  j  a  v  a2  s .c om*/
 * @param <T> type of collection
 * @param col1 the first collection
 * @param col2 the second collection
 * @return <code>null</code> if col1 contains all of col2, else return the extra items that col2
 *         have.
 */
static public <T> Set<T> contains(final Set<T> col1, final Set<T> col2) {
    if (col1.containsAll(col2))
        return null;
    else {
        final Set<T> names = new HashSet<T>(col2);
        names.removeAll(col1);
        return names;
    }
}

From source file:domainregistry.AdvancedSearch.java

public static Map<String, HypertyInstance> getHyperties(Map<String, String> parameters,
        Map<String, HypertyInstance> data) {
    Map<String, HypertyInstance> foundHyperties = new HashMap();

    for (Map.Entry<String, HypertyInstance> entry : data.entrySet()) {
        HypertyInstance hyperty = entry.getValue();

        List<String> dataSchemesTypes = map(hyperty.getDataSchemes(), SCHEMES_PREFIX);
        List<String> resourcesTypes = map(hyperty.getResources(), RESOURCES_PREFIX);

        List<String> hypertyParams = new ArrayList<String>(dataSchemesTypes);
        hypertyParams.addAll(resourcesTypes);
        Set hypertyParamsSet = new HashSet(hypertyParams);

        if (hypertyParamsSet.containsAll(new HashSet<String>(getQueryParams(parameters)))) {
            foundHyperties.put(entry.getKey(), hyperty);
        }/* w  w  w . ja v  a  2s  .  c  o  m*/
    }

    return foundHyperties;
}