Example usage for java.util LinkedHashSet retainAll

List of usage examples for java.util LinkedHashSet retainAll

Introduction

In this page you can find the example usage for java.util LinkedHashSet retainAll.

Prototype

boolean retainAll(Collection<?> c);

Source Link

Document

Retains only the elements in this set that are contained in the specified collection (optional operation).

Usage

From source file:jenkins.plugins.ivyreport.IvyAccess.java

String[] expandConfs(String[] requested) {
    if (moduleDescriptor == null) {
        recomputeModuleDescriptor();//from  w  w w. j  a  va 2  s.c  om
        if (moduleDescriptor == null) {
            return requested;
        }
    }
    String[] expanded = ConfigurationUtils.replaceWildcards(requested, moduleDescriptor);
    LinkedHashSet<String> result = new LinkedHashSet<String>();
    Collections.addAll(result, expanded);
    result.retainAll(Arrays.asList(moduleDescriptor.getConfigurationsNames()));
    return result.toArray(new String[result.size()]);
}

From source file:org.mskcc.cbio.importer.converter.internal.ConverterImpl.java

/**
 * Generates case lists for the given portal.
 *
  * @param portal String/*from w  w w.  j  a v a  2 s  .  c  om*/
 * @throws Exception
 */
@Override
public void generateCaseLists(String portal) throws Exception {

    if (LOG.isInfoEnabled()) {
        LOG.info("generateCaseLists()");
    }

    // check args
    if (portal == null) {
        throw new IllegalArgumentException("portal must not be null");
    }

    // get portal metadata
    PortalMetadata portalMetadata = config.getPortalMetadata(portal).iterator().next();
    if (portalMetadata == null) {
        if (LOG.isInfoEnabled()) {
            LOG.info("convertData(), cannot find PortalMetadata, returning");
        }
        return;
    }

    // get CaseListMetadata
    Collection<CaseListMetadata> caseListMetadatas = config.getCaseListMetadata(Config.ALL);

    // iterate over all cancer studies
    for (CancerStudyMetadata cancerStudyMetadata : config.getCancerStudyMetadata(portalMetadata.getName())) {
        // iterate over case lists
        for (CaseListMetadata caseListMetadata : caseListMetadatas) {
            if (LOG.isInfoEnabled()) {
                LOG.info("generateCaseLists(), processing cancer study: " + cancerStudyMetadata
                        + ", case list: " + caseListMetadata.getCaseListFilename());
            }
            // how many staging files are we working with?
            String[] stagingFilenames = null;
            // setup union/intersection bools
            boolean unionCaseList = caseListMetadata.getStagingFilenames()
                    .contains(CaseListMetadata.CASE_LIST_UNION_DELIMITER);
            boolean intersectionCaseList = caseListMetadata.getStagingFilenames()
                    .contains(CaseListMetadata.CASE_LIST_INTERSECTION_DELIMITER);
            // union (like all cases)
            if (unionCaseList) {
                stagingFilenames = caseListMetadata.getStagingFilenames()
                        .split("\\" + CaseListMetadata.CASE_LIST_UNION_DELIMITER);
            }
            // intersection (like complete or cna-seq)
            else if (intersectionCaseList) {
                stagingFilenames = caseListMetadata.getStagingFilenames()
                        .split("\\" + CaseListMetadata.CASE_LIST_INTERSECTION_DELIMITER);
            }
            // just a single staging file
            else {
                stagingFilenames = new String[] { caseListMetadata.getStagingFilenames() };
            }
            if (LOG.isInfoEnabled()) {
                LOG.info("generateCaseLists(), stagingFilenames: "
                        + java.util.Arrays.toString(stagingFilenames));
            }
            // this is the set we will pass to writeCaseListFile
            LinkedHashSet<String> caseSet = new LinkedHashSet<String>();
            // this indicates the number of staging files processed -
            // used to verify that an intersection should be written
            int numStagingFilesProcessed = 0;
            for (String stagingFilename : stagingFilenames) {
                if (LOG.isInfoEnabled()) {
                    LOG.info("generateCaseLists(), processing stagingFile: " + stagingFilename);
                }
                // compute the case set
                List<String> caseList = fileUtils.getCaseListFromStagingFile(caseIDs, portalMetadata,
                        cancerStudyMetadata, stagingFilename);
                // we may not have this datatype in study
                if (caseList.size() == 0) {
                    if (LOG.isInfoEnabled()) {
                        LOG.info("generateCaseLists(), stagingFileHeader is empty: " + stagingFilename
                                + ", skipping...");
                    }
                    continue;
                }
                // intersection 
                if (intersectionCaseList) {
                    if (caseSet.isEmpty()) {
                        caseSet.addAll(caseList);
                    } else {
                        caseSet.retainAll(caseList);
                    }
                }
                // otherwise union or single staging (treat the same)
                else {
                    caseSet.addAll(caseList);
                }
                ++numStagingFilesProcessed;
            }
            // write the case list file (don't make empty case lists)
            if (caseSet.size() > 0) {
                if (LOG.isInfoEnabled()) {
                    LOG.info("generateCaseLists(), calling writeCaseListFile()...");
                }
                // do not write out complete cases file unless we've processed all the files required
                if (intersectionCaseList && (numStagingFilesProcessed != stagingFilenames.length)) {
                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                                "generateCaseLists(), number of staging files processed != number staging files required for cases_complete.txt, skipping call to writeCaseListFile()...");
                    }
                    continue;
                }
                fileUtils.writeCaseListFile(portalMetadata, cancerStudyMetadata, caseListMetadata,
                        caseSet.toArray(new String[0]));
            } else if (LOG.isInfoEnabled()) {
                LOG.info("generateCaseLists(), caseSet.size() <= 0, skipping call to writeCaseListFile()...");
            }
            // if union, write out the cancer study metadata file
            if (caseSet.size() > 0 && caseListMetadata.getCaseListFilename().equals(ALL_CASES_FILENAME)) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(
                            "generateCaseLists(), processed all cases list, we can now update cancerStudyMetadata file()...");
                }
                fileUtils.writeCancerStudyMetadataFile(portalMetadata, cancerStudyMetadata, caseSet.size());
            }
        }
    }

}