Example usage for java.util TreeSet addAll

List of usage examples for java.util TreeSet addAll

Introduction

In this page you can find the example usage for java.util TreeSet addAll.

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Adds all of the elements in the specified collection to this set.

Usage

From source file:org.deegree.enterprise.WebUtils.java

private static void handleProxies(String protocol, HttpClient client, String host) {
    TreeSet<String> nops = new TreeSet<String>();

    String proxyHost = getProperty((protocol == null ? "" : protocol + ".") + "proxyHost");

    String proxyUser = getProperty((protocol == null ? "" : protocol + ".") + "proxyUser");
    String proxyPass = getProperty((protocol == null ? "" : protocol + ".") + "proxyPassword");

    if (proxyHost != null) {
        String nop = getProperty((protocol == null ? "" : protocol + ".") + "noProxyHosts");
        if (nop != null && !nop.equals("")) {
            nops.addAll(asList(nop.split("\\|")));
        }/*w ww.  ja  v a  2s  .  c om*/
        nop = getProperty((protocol == null ? "" : protocol + ".") + "nonProxyHosts");
        if (nop != null && !nop.equals("")) {
            nops.addAll(asList(nop.split("\\|")));
        }

        int proxyPort = parseInt(getProperty((protocol == null ? "" : protocol + ".") + "proxyPort"));

        HostConfiguration hc = client.getHostConfiguration();

        if (LOG.isDebug()) {
            LOG.logDebug("Found the following no- and nonProxyHosts", nops);
        }

        if (proxyUser != null) {
            Credentials creds = new UsernamePasswordCredentials(proxyUser, proxyPass);
            client.getState().setProxyCredentials(AuthScope.ANY, creds);
            client.getParams().setAuthenticationPreemptive(true);
        }

        if (!nops.contains(host)) {
            if (LOG.isDebug()) {
                LOG.logDebug("Using proxy " + proxyHost + ":" + proxyPort);
                if (protocol == null) {
                    LOG.logDebug("This overrides the protocol specific settings, if there were any.");
                }
            }
            hc.setProxy(proxyHost, proxyPort);
            client.setHostConfiguration(hc);
        } else {
            if (LOG.isDebug()) {
                LOG.logDebug("Proxy was set, but " + host + " was contained in the no-/nonProxyList!");
                if (protocol == null) {
                    LOG.logDebug("If a protocol specific proxy has been set, it will be used anyway!");
                }
            }
        }
    }

    if (protocol != null) {
        handleProxies(null, client, host);
    }
}

From source file:uk.ac.ebi.intact.util.protein.utils.AliasUpdaterUtils.java

public static AliasUpdateReport updateAliases(UniprotProtein uniprotProtein, Protein protein, AliasDao aliasDao,
        TreeSet<InteractorAlias> sortedAliases) {

    sortedAliases.clear();//  w  w  w .  jav  a 2  s. c o m
    sortedAliases.addAll(protein.getAliases());
    Iterator<InteractorAlias> intactIterator = sortedAliases.iterator();

    AliasUpdateReport report = new AliasUpdateReport(protein);

    // process genes
    TreeSet<String> geneNames = new TreeSet<String>(uniprotProtein.getGenes());
    Iterator<String> geneIterator = geneNames.iterator();
    InteractorAlias currentIntact = null;

    if (geneIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, null, intactIterator, geneIterator,
                CvAliasType.GENE_NAME_MI_REF, report, aliasDao);
    }

    // process synonyms
    TreeSet<String> geneSynonyms = new TreeSet<String>(uniprotProtein.getSynomyms());
    Iterator<String> geneSynonymsIterator = geneSynonyms.iterator();

    if (geneSynonymsIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, currentIntact, intactIterator, geneSynonymsIterator,
                CvAliasType.GENE_NAME_SYNONYM_MI_REF, report, aliasDao);
    }

    // process orfs
    TreeSet<String> orfs = new TreeSet<String>(uniprotProtein.getOrfs());
    Iterator<String> orfsIterator = orfs.iterator();

    if (orfsIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, currentIntact, intactIterator, orfsIterator,
                CvAliasType.ORF_NAME_MI_REF, report, aliasDao);
    }

    // process locus
    TreeSet<String> locuses = new TreeSet<String>(uniprotProtein.getLocuses());
    Iterator<String> locusesIterator = locuses.iterator();

    if (locusesIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, currentIntact, intactIterator, locusesIterator,
                CvAliasType.LOCUS_NAME_MI_REF, report, aliasDao);
    }

    // delete remaining aliases
    if (currentIntact != null || intactIterator.hasNext()) {
        if (currentIntact == null) {
            currentIntact = intactIterator.next();
        }

        do {
            protein.removeAlias(currentIntact);
            report.getRemovedAliases().add(currentIntact);

            aliasDao.delete(currentIntact);

            if (intactIterator.hasNext()) {
                currentIntact = intactIterator.next();
            } else {
                currentIntact = null;
            }
        } while (currentIntact != null);
    }

    sortedAliases.clear();
    return report;
}

From source file:uk.ac.ebi.intact.util.protein.utils.AliasUpdaterUtils.java

public static AliasUpdateReport updateIsoformAliases(UniprotProtein master,
        UniprotProteinTranscript uniprotProteinTranscript, Protein protein, AliasDao aliasDao,
        TreeSet<InteractorAlias> sortedAliases) {

    sortedAliases.clear();/*from  w  w w  .  ja v a 2 s .  c  o  m*/
    sortedAliases.addAll(protein.getAliases());
    Iterator<InteractorAlias> intactIterator = sortedAliases.iterator();

    AliasUpdateReport report = new AliasUpdateReport(protein);

    // process genes
    TreeSet<String> geneNames = new TreeSet<String>(master.getGenes());
    Iterator<String> geneIterator = geneNames.iterator();

    InteractorAlias currentIntact = null;

    if (geneIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, null, intactIterator, geneIterator,
                CvAliasType.GENE_NAME_MI_REF, report, aliasDao);
    }

    // process synonyms
    TreeSet<String> geneSynonyms = new TreeSet<String>(master.getSynomyms());
    Iterator<String> geneSynonymsIterator = geneSynonyms.iterator();

    if (geneSynonymsIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, currentIntact, intactIterator, geneSynonymsIterator,
                CvAliasType.GENE_NAME_SYNONYM_MI_REF, report, aliasDao);
    }

    // process orfs
    TreeSet<String> orfs = new TreeSet<String>(master.getOrfs());
    Iterator<String> orfsIterator = orfs.iterator();

    if (orfsIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, currentIntact, intactIterator, orfsIterator,
                CvAliasType.ORF_NAME_MI_REF, report, aliasDao);
    }

    // process locus
    TreeSet<String> locuses = new TreeSet<String>(master.getLocuses());
    Iterator<String> locusesIterator = locuses.iterator();

    if (locusesIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, currentIntact, intactIterator, locusesIterator,
                CvAliasType.LOCUS_NAME_MI_REF, report, aliasDao);
    }

    // process isoform synonyms
    TreeSet<String> isoformSynonyms = new TreeSet<String>(uniprotProteinTranscript.getSynomyms());
    Iterator<String> isoformSynonymsIterator = isoformSynonyms.iterator();

    if (isoformSynonymsIterator.hasNext()) {
        currentIntact = compareAndUpdateAliases(protein, currentIntact, intactIterator, isoformSynonymsIterator,
                CvAliasType.ISOFORM_SYNONYM_MI_REF, report, aliasDao);
    }

    // delete remaining aliases
    if (currentIntact != null || intactIterator.hasNext()) {
        if (currentIntact == null) {
            currentIntact = intactIterator.next();
        }
        do {
            protein.removeAlias(currentIntact);
            report.getRemovedAliases().add(currentIntact);

            aliasDao.delete(currentIntact);

            if (intactIterator.hasNext()) {
                currentIntact = intactIterator.next();
            } else {
                currentIntact = null;
            }
        } while (currentIntact != null);
    }

    sortedAliases.clear();
    return report;
}

From source file:org.broadinstitute.gatk.utils.haplotype.EventMap.java

/**
 * Build event maps for each haplotype, returning the sorted set of all of the starting positions of all
 * events across all haplotypes/*from   w ww . j a va2s.  c  o  m*/
 *
 * @param haplotypes a list of haplotypes
 * @param ref the reference bases
 * @param refLoc the span of the reference bases
 * @param debug if true, we'll emit debugging information during this operation
 * @return a sorted set of start positions of all events among all haplotypes
 */
public static TreeSet<Integer> buildEventMapsForHaplotypes(final List<Haplotype> haplotypes, final byte[] ref,
        final GenomeLoc refLoc, final boolean debug) {
    // Using the cigar from each called haplotype figure out what events need to be written out in a VCF file
    final TreeSet<Integer> startPosKeySet = new TreeSet<Integer>();
    int hapNumber = 0;

    if (debug)
        logger.info("=== Best Haplotypes ===");
    for (final Haplotype h : haplotypes) {
        // Walk along the alignment and turn any difference from the reference into an event
        h.setEventMap(new EventMap(h, ref, refLoc, "HC" + hapNumber++));
        startPosKeySet.addAll(h.getEventMap().getStartPositions());

        if (debug) {
            logger.info(h.toString());
            logger.info("> Cigar = " + h.getCigar());
            logger.info(">> Events = " + h.getEventMap());
        }
    }

    return startPosKeySet;
}

From source file:base.Engine.java

static Set<TreeSet<PatternInstance>> resolveTree(Set<TreeSet<PatternInstance>> returnSet,
        Set<PatternInstance> colls) {
    TreeSet<PatternInstance> workingTree = new TreeSet<>(new InstanceComparator());
    for (PatternInstance p : colls) {
        TreeSet<PatternInstance> onThisTree = null;
        for (TreeSet<PatternInstance> it : returnSet) {
            if (it.contains(p)) {
                onThisTree = it;/*from w ww  .  j ava2 s.co m*/
                break;
            }
        }

        if (onThisTree == null) {
            workingTree.add(p);
        } else {
            workingTree.addAll(onThisTree);
            returnSet.remove(onThisTree);
        }
    }
    returnSet.add(workingTree);
    return returnSet;
}

From source file:com.linkedin.helix.TestHelper.java

public static void printCache(Map<String, ZNode> cache) {
    System.out.println("START:Print cache");
    TreeMap<String, ZNode> map = new TreeMap<String, ZNode>();
    map.putAll(cache);/*from w w w .  ja  va2s  .  com*/

    for (String key : map.keySet()) {
        ZNode node = map.get(key);
        TreeSet<String> childSet = new TreeSet<String>();
        childSet.addAll(node.getChildSet());
        System.out.print(key + "=" + node.getData() + ", " + childSet + ", "
                + (node.getStat() == null ? "null\n" : node.getStat()));
    }
    System.out.println("END:Print cache");
}

From source file:org.deegree.commons.utils.net.HttpUtils.java

private static void handleProxies(String protocol, HttpClient client, String host) {
    TreeSet<String> nops = new TreeSet<String>();

    String proxyHost = getProperty((protocol == null ? "" : protocol + ".") + "proxyHost");

    String proxyUser = getProperty((protocol == null ? "" : protocol + ".") + "proxyUser");
    String proxyPass = getProperty((protocol == null ? "" : protocol + ".") + "proxyPassword");

    if (proxyHost != null) {
        String nop = getProperty((protocol == null ? "" : protocol + ".") + "noProxyHosts");
        if (nop != null && !nop.equals("")) {
            nops.addAll(asList(nop.split("\\|")));
        }/*from  w  w  w  . j  a  v  a  2s . com*/
        nop = getProperty((protocol == null ? "" : protocol + ".") + "nonProxyHosts");
        if (nop != null && !nop.equals("")) {
            nops.addAll(asList(nop.split("\\|")));
        }

        int proxyPort = parseInt(getProperty((protocol == null ? "" : protocol + ".") + "proxyPort"));

        HostConfiguration hc = client.getHostConfiguration();

        if (LOG.isDebugEnabled()) {
            LOG.debug("Found the following no- and nonProxyHosts: {}", nops);
        }

        if (proxyUser != null) {
            Credentials creds = new UsernamePasswordCredentials(proxyUser, proxyPass);
            client.getState().setProxyCredentials(AuthScope.ANY, creds);
            client.getParams().setAuthenticationPreemptive(true);
        }

        if (!nops.contains(host)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Using proxy {}:{}", proxyHost, proxyPort);
                if (protocol == null) {
                    LOG.debug("This overrides the protocol specific settings, if there were any.");
                }
            }
            hc.setProxy(proxyHost, proxyPort);
            client.setHostConfiguration(hc);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Proxy was set, but {} was contained in the no-/nonProxyList!", host);
                if (protocol == null) {
                    LOG.debug("If a protocol specific proxy has been set, it will be used anyway!");
                }
            }
        }
    }

    if (protocol != null) {
        handleProxies(null, client, host);
    }
}

From source file:org.apache.hadoop.hbase.backup.util.BackupUtils.java

public static boolean validate(HashMap<TableName, BackupManifest> backupManifestMap, Configuration conf)
        throws IOException {
    boolean isValid = true;

    for (Entry<TableName, BackupManifest> manifestEntry : backupManifestMap.entrySet()) {
        TableName table = manifestEntry.getKey();
        TreeSet<BackupImage> imageSet = new TreeSet<BackupImage>();

        ArrayList<BackupImage> depList = manifestEntry.getValue().getDependentListByTable(table);
        if (depList != null && !depList.isEmpty()) {
            imageSet.addAll(depList);
        }//www.  j  av  a2 s  .  c o m

        LOG.info("Dependent image(s) from old to new:");
        for (BackupImage image : imageSet) {
            String imageDir = HBackupFileSystem.getTableBackupDir(image.getRootDir(), image.getBackupId(),
                    table);
            if (!BackupUtils.checkPathExist(imageDir, conf)) {
                LOG.error("ERROR: backup image does not exist: " + imageDir);
                isValid = false;
                break;
            }
            LOG.info("Backup image: " + image.getBackupId() + " for '" + table + "' is available");
        }
    }
    return isValid;
}

From source file:com.genentech.application.calcProps.SDFCalcProps.java

/**
 * Get the list of SD tags that a property produces
 * also gets the tags that are produced by calculators this property depends on aka "required tags"
 * "required tags" are defined in the keepRequiredCalculators field on the XML files
*//*w w w .  ja  v  a2s .c o  m*/
private static TreeSet<String> getOutputFields(String prop, Set<Calculator> calculators, boolean verbose) {
    TreeSet<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    for (Calculator calc : calculators) {
        if (calc.getName().equals(prop)) {
            //add tags for calculator
            tags.addAll(calc.getOutputFields());
            if (verbose) {
                tags.addAll(calc.getVerboseFields());
            }
            //get tags for keepRequiredCalculators, recursively
            Set<String> requiredCalcs = calc.getKeepRequiredCalculators();
            for (String c : requiredCalcs) {
                tags.addAll(getOutputFields(c, calculators, verbose));
            }
        }
    }
    return tags;
}

From source file:org.broadinstitute.sting.utils.codecs.vcf.VCFUtils.java

/**
 * Gets the header fields from all VCF rods input by the user
 *
 * @param toolkit    GATK engine/*from  w ww .  jav  a  2  s.  c o  m*/
 * @param rodNames   names of rods to use, or null if we should use all possible ones
 *
 * @return a set of all fields
 */
public static Set<VCFHeaderLine> getHeaderFields(GenomeAnalysisEngine toolkit, Collection<String> rodNames) {

    // keep a map of sample name to occurrences encountered
    TreeSet<VCFHeaderLine> fields = new TreeSet<VCFHeaderLine>();

    // iterate to get all of the sample names
    List<ReferenceOrderedDataSource> dataSources = toolkit.getRodDataSources();
    for (ReferenceOrderedDataSource source : dataSources) {
        // ignore the rod if it's not in our list
        if (rodNames != null && !rodNames.contains(source.getName()))
            continue;

        if (source.getRecordType().equals(VariantContext.class)) {
            VCFHeader header = (VCFHeader) source.getHeader();
            if (header != null)
                fields.addAll(header.getMetaDataInSortedOrder());
        }
    }

    return fields;
}