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:net.spfbl.data.Generic.java

public static TreeSet<String> getGenericAll() throws ProcessException {
    TreeSet<String> set = MAP.getGenericAll();
    set.addAll(REGEX.getAll());
    return set;//from www.  j av a  2s .  c  om
}

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

private static String calculate(String[] props, boolean predictTautomer, boolean dontFilter, boolean verbose,
        boolean debug, boolean printOnly, boolean addMolIndex, Set<Calculator> availCALCS, String inFile,
        String outFile) throws IOException, InterruptedException {
    String counterTag = "___sdfCalcProps_counter___";
    String savedTitleTag = "___sdfCalcProps_saved_title___";
    String tempFileRoot = "/tmp/sdfCalcProps.$$." + System.currentTimeMillis();
    String tempOrigFileName = tempFileRoot + ".orig.sdf";
    String filteredFileName = tempFileRoot + ".filtered.sdf";

    Set<Calculator> calculators = new LinkedHashSet<Calculator>();

    //Properties that depend on ionization state of the molecule ex. charge
    Set<Calculator> ionizedCalculators = new LinkedHashSet<Calculator>();
    //Properties that depend on the neutral molecule. ex. MW
    Set<Calculator> neutralCalculators = new LinkedHashSet<Calculator>();

    for (String prop : props) {
        //getCalculators takes care of getting all dependent calculators, recursively
        Set<Calculator> myCalcs = getCalculators(prop, availCALCS);

        //adding to a set, does not contain duplicates calculators
        calculators.addAll(myCalcs);//from   w w  w.  ja  v a  2 s . c  o  m
    }

    //divide calculators into those that require ionization and those that don't
    for (Calculator calc : calculators) {
        if (calc.requiresIonization()) {
            ionizedCalculators.add(calc);
        } else {
            neutralCalculators.add(calc);
        }
    }

    //get the set of SD tags that will be produced, each property produces a set of SD tags
    //using TreeSet to keep the SD tags in alphabetical order
    TreeSet<String> ionizedOutputTags = new TreeSet<String>();
    for (Calculator p : ionizedCalculators) {
        ionizedOutputTags.addAll(getOutputFields(p.getName(), ionizedCalculators, verbose));
    }

    TreeSet<String> neutralOutputTags = new TreeSet<String>();
    for (Calculator p : neutralCalculators) {
        neutralOutputTags.addAll(getOutputFields(p.getName(), neutralCalculators, verbose));
    }

    // The list of SD tags that will be produced
    // this set should be a union of tags from ionized and neutral tags
    // I guess I could just merge the treesets from ionized and neutral tags
    TreeSet<String> allOutputTags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    for (String prop : props) {
        allOutputTags.addAll(getOutputFields(prop, calculators, verbose));
    }

    if (debug) {
        System.err.println("=============================================");
        System.err.println("The following properties will be calculated.");
        printProperties(calculators, true);

        System.err.println("The following tags will be produced.");
        for (String t : allOutputTags) {
            System.err.print(t + " ");
        }
        System.err.println();
    }

    //The following tags will be produced, exit after printing
    if (printOnly) {
        StringBuilder outputTags = assembleTags(allOutputTags);
        System.out.println("echo '" + outputTags + "'");
        System.exit(0);
    }

    // special properties that dictate how molecules are preprocessed
    Calculator tautomerCalculator = null;
    Calculator filterCalculator = null;
    Calculator ionizeCalculator = null;
    for (Calculator calc : availCALCS) {
        if (calc.getName().equals("predictTautomer")) {
            tautomerCalculator = calc;
        }
        if (calc.getName().equals("filter")) {
            filterCalculator = calc;
        }
        if (calc.getName().equals("ionize")) {
            ionizeCalculator = calc;
        }
    }

    // assemble the command line base on the properties that were requested,
    // this is the most complicated part of this program "assembleCommands"

    //get a string of piped commands for calculating properties that depend on ionization state
    ionizedCalculators = consolidateByAggregationId(ionizedCalculators);
    String ionizedCommand = assembleCommands(ionizedCalculators, verbose, debug, counterTag, ionizedOutputTags);
    if (ionizedCommand != null) {
        //prepend command to generated ionized molecules
        ionizedCommand = ionizeCalculator.getProgName() + " " + ionizeCalculator.getProgOps() + " | "
                + ionizedCommand;
    }

    //get a string of piped commands for calculating properties on the neutral molecule
    neutralCalculators = consolidateByAggregationId(neutralCalculators);
    String neutralCommand = assembleCommands(neutralCalculators, verbose, debug, counterTag, allOutputTags);

    //save a temp file that contains a unique identifier
    //run filter to get rid of "bad" molecules
    String command = "sdfTagTool.csh -copy TITLE=" + savedTitleTag + " -addCounter -counterTag " + counterTag
            + " -title " + counterTag + " -in " + inFile + " -out .sdf | tee " + tempOrigFileName + " | "
            + filterCalculator.getProgName() + " " + filterCalculator.getProgOps()
            + " | sdfTagTool.csh -in .sdf -out .sdf -keep " + counterTag;

    //different command if not filtering
    if (dontFilter) {
        command = "sdfTagTool.csh -copy TITLE=" + savedTitleTag + " -addCounter -counterTag " + counterTag
                + " -title " + counterTag + " -in " + inFile + " -out .sdf | tee " + tempOrigFileName
                + " | sdfTagTool.csh -in .sdf -out .sdf -keep " + counterTag;
    }

    String cleanUpCommand = "sdfTagTool.csh -in .sdf -title " + savedTitleTag + " -out .sdf "
            + " | sdfTagTool.csh -in .sdf -remove \"" + counterTag + "|" + savedTitleTag + "\" -out " + outFile;

    //command to create a Mol_Index tag for each molecule
    if (addMolIndex) {
        cleanUpCommand = "sdfTagTool.csh -in .sdf -title " + savedTitleTag + " -out .sdf "
                + " -format 'Mol_Index=Mol_{" + counterTag + "}'" + " | sdfTagTool.csh -in .sdf -remove \""
                + counterTag + "|" + savedTitleTag + "\" -out " + outFile;
    }

    //predict tautomer
    if (predictTautomer) {
        command = command + " | " + tautomerCalculator.getProgName() + " " + tautomerCalculator.getProgOps()
                + " > " + filteredFileName;
    } else {
        command = command + " > " + filteredFileName;
    }

    //      command = command + "; cat " + filteredFileName;
    command = command + "; echo NCCO | babel -in .smi -out .sdf >> " + filteredFileName + "; cat "
            + filteredFileName;

    if (ionizedCommand != null && neutralCommand != null) {
        // merge temp file with the two tab files
        String mergeCommand = "sdfTabMerger.csh -sdf " + tempOrigFileName + " -tab -  -mergeTag " + counterTag
                + " -mergeCol " + counterTag + " -out .sdf | " + cleanUpCommand;
        command = command + " | " + ionizedCommand + " | sdfTabMerger.csh -tab - -sdf " + filteredFileName
                + " -mergeTag " + counterTag + " -mergeCol " + counterTag + "  -out .sdf | " + neutralCommand
                + " | " + mergeCommand;
    } else if (ionizedCommand == null && neutralCommand != null) {
        String mergeCommand = "sdfTabMerger.csh -sdf " + tempOrigFileName + " -tab - -mergeTag " + counterTag
                + " -mergeCol " + counterTag + " -out .sdf | " + cleanUpCommand;

        command = command + " | " + neutralCommand + " | " + mergeCommand;
    } else if (ionizedCommand != null && neutralCommand == null) {
        String mergeCommand = "sdfTabMerger.csh -sdf " + tempOrigFileName + " -tab - -mergeTag " + counterTag
                + " -mergeCol " + counterTag + " -out .sdf | " + cleanUpCommand;

        command = command + " | " + ionizedCommand + " | " + mergeCommand;
    }

    if (debug) {
        System.err.println("ionized command:\n" + ionizedCommand);
        System.err.println("neutral command:\n" + neutralCommand);
        System.err.println("Command to be executed:\n" + command);
    }

    return (command);
}

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

public static XrefUpdaterReport updateAllXrefs(Protein protein, UniprotProtein uniprotProtein,
        Map<String, String> databaseName2mi, DataContext context, ProteinUpdateProcessor processor,
        TreeSet<InteractorXref> sortedXrefs, TreeSet<UniprotXref> sortedUniprotXrefs) {

    sortedXrefs.clear();//from w ww . j a  v  a  2  s. co m
    sortedXrefs.addAll(protein.getXrefs());
    Iterator<InteractorXref> intactIterator = sortedXrefs.iterator();

    sortedUniprotXrefs.clear();
    sortedUniprotXrefs.addAll(uniprotProtein.getCrossReferences());
    Iterator<UniprotXref> uniprotIterator = sortedUniprotXrefs.iterator();

    List<Xref> createdXrefs = new ArrayList<Xref>(uniprotProtein.getCrossReferences().size());
    List<Xref> deletedXrefs = new ArrayList<Xref>(protein.getXrefs().size());

    DaoFactory daoFactory = context.getDaoFactory();
    CvObjectDao<CvDatabase> dbDao = daoFactory.getCvObjectDao(CvDatabase.class);
    XrefDao<InteractorXref> refDao = daoFactory.getXrefDao(InteractorXref.class);

    InteractorXref currentIntact = null;
    UniprotXref currentUniprot = null;
    String db = null;
    CvDatabase cvDatabase = null;

    if (intactIterator.hasNext() && uniprotIterator.hasNext()) {
        currentIntact = intactIterator.next();
        currentUniprot = uniprotIterator.next();
        db = databaseName2mi.get(currentUniprot.getDatabase().toLowerCase());
        cvDatabase = currentIntact.getCvDatabase();

        if (db != null && cvDatabase != null) {
            do {
                int dbComparator = cvDatabase.getIdentifier().compareTo(db);

                if (dbComparator == 0) {
                    int acComparator = currentIntact.getPrimaryId().compareTo(currentUniprot.getAccession());

                    if (acComparator == 0) {
                        if (intactIterator.hasNext() && uniprotIterator.hasNext()) {
                            currentIntact = intactIterator.next();
                            currentUniprot = uniprotIterator.next();
                            db = databaseName2mi.get(currentUniprot.getDatabase().toLowerCase());
                            cvDatabase = currentIntact.getCvDatabase();
                        } else {
                            currentIntact = null;
                            currentUniprot = null;
                            db = null;
                            cvDatabase = null;
                        }
                    } else if (acComparator < 0) {
                        //intact has no match in uniprot
                        if (!CvDatabase.UNIPROT_MI_REF.equalsIgnoreCase(cvDatabase.getIdentifier())
                                && !CvDatabase.INTACT_MI_REF
                                        .equalsIgnoreCase(currentIntact.getCvDatabase().getIdentifier())
                                && !(currentIntact.getCvXrefQualifier() != null && ("intact-secondary"
                                        .equalsIgnoreCase(currentIntact.getCvXrefQualifier().getShortLabel())
                                        || CvXrefQualifier.SECONDARY_AC.equalsIgnoreCase(
                                                currentIntact.getCvXrefQualifier().getShortLabel())))) {
                            deletedXrefs.add(currentIntact);
                            protein.removeXref(currentIntact);

                            refDao.delete(currentIntact);
                        }

                        if (intactIterator.hasNext()) {
                            currentIntact = intactIterator.next();
                            cvDatabase = currentIntact.getCvDatabase();
                        } else {
                            currentIntact = null;
                            cvDatabase = null;
                        }
                    } else {
                        //uniprot has no match in intact
                        CvDatabase cvDb = cvDatabase;

                        InteractorXref newXref = new InteractorXref(
                                IntactContext.getCurrentInstance().getInstitution(), cvDb,
                                currentUniprot.getAccession(), null);
                        protein.addXref(newXref);

                        refDao.persist(newXref);

                        createdXrefs.add(newXref);

                        if (uniprotIterator.hasNext()) {
                            currentUniprot = uniprotIterator.next();
                            db = databaseName2mi.get(currentUniprot.getDatabase().toLowerCase());
                        } else {
                            currentUniprot = null;
                            db = null;
                        }
                    }
                } else if (dbComparator < 0) {
                    //intact has no match in uniprot
                    if (!CvDatabase.UNIPROT_MI_REF
                            .equalsIgnoreCase(currentIntact.getCvDatabase().getIdentifier())
                            && !CvDatabase.INTACT_MI_REF
                                    .equalsIgnoreCase(currentIntact.getCvDatabase().getIdentifier())
                            && !(currentIntact.getCvXrefQualifier() != null && ("intact-secondary"
                                    .equalsIgnoreCase(currentIntact.getCvXrefQualifier().getShortLabel())
                                    || CvXrefQualifier.SECONDARY_AC.equalsIgnoreCase(
                                            currentIntact.getCvXrefQualifier().getShortLabel())))) {
                        deletedXrefs.add(currentIntact);
                        protein.removeXref(currentIntact);

                        refDao.delete(currentIntact);
                    }
                    if (intactIterator.hasNext()) {
                        currentIntact = intactIterator.next();
                        cvDatabase = currentIntact.getCvDatabase();
                    } else {
                        currentIntact = null;
                        cvDatabase = null;
                    }
                } else {
                    //uniprot has no match in intact
                    CvDatabase cvDb = dbDao.getByIdentifier(db);

                    if (cvDb != null) {

                        InteractorXref newXref = new InteractorXref(
                                IntactContext.getCurrentInstance().getInstitution(), cvDb,
                                currentUniprot.getAccession(), null);
                        protein.addXref(newXref);

                        refDao.persist(newXref);

                        createdXrefs.add(newXref);

                    } else {
                        log.debug("We are not copying across xref to " + db);
                    }

                    if (uniprotIterator.hasNext()) {
                        currentUniprot = uniprotIterator.next();
                        db = databaseName2mi.get(currentUniprot.getDatabase().toLowerCase());
                    } else {
                        currentUniprot = null;
                        db = null;
                    }
                }
            } while (currentIntact != null && currentUniprot != null && db != null && cvDatabase != null);
        }
    }

    if (currentIntact != null || intactIterator.hasNext()) {
        if (currentIntact == null) {
            currentIntact = intactIterator.next();
            cvDatabase = currentIntact.getCvDatabase();
        }

        do {
            //intact has no match in uniprot
            if (cvDatabase == null || (cvDatabase != null
                    && !CvDatabase.UNIPROT_MI_REF.equalsIgnoreCase(cvDatabase.getIdentifier())
                    && !CvDatabase.INTACT_MI_REF.equalsIgnoreCase(cvDatabase.getIdentifier())
                    && !(currentIntact.getCvXrefQualifier() != null && ("intact-secondary"
                            .equalsIgnoreCase(currentIntact.getCvXrefQualifier().getShortLabel())
                            || CvXrefQualifier.SECONDARY_AC
                                    .equalsIgnoreCase(currentIntact.getCvXrefQualifier().getShortLabel()))))) {
                deletedXrefs.add(currentIntact);

                protein.removeXref(currentIntact);

                refDao.delete(currentIntact);
            }

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

    if (currentUniprot != null || uniprotIterator.hasNext()) {
        if (currentUniprot == null) {
            currentUniprot = uniprotIterator.next();
            db = databaseName2mi.get(currentUniprot.getDatabase().toLowerCase());
        }

        if (db != null) {
            do {
                //uniprot has no match in intact
                CvDatabase cvDb = dbDao.getByIdentifier(db);

                if (cvDb != null) {

                    InteractorXref newXref = new InteractorXref(
                            IntactContext.getCurrentInstance().getInstitution(), cvDb,
                            currentUniprot.getAccession(), null);
                    protein.addXref(newXref);

                    refDao.persist(newXref);

                    createdXrefs.add(newXref);

                } else {
                    log.debug("We are not copying across xref to " + db);
                }

                if (uniprotIterator.hasNext()) {
                    currentUniprot = uniprotIterator.next();
                    db = databaseName2mi.get(currentUniprot.getDatabase().toLowerCase());
                } else {
                    currentUniprot = null;
                    db = null;
                }
            } while (currentUniprot != null && db != null);
        }
    }

    // update uniprot xrefs
    XrefUpdaterReport report = updateUniprotXrefs(protein, uniprotProtein, context, processor);

    if (report == null && (!createdXrefs.isEmpty() || !deletedXrefs.isEmpty())) {
        report = new XrefUpdaterReport(protein, createdXrefs, deletedXrefs);

    } else if (report != null && (!createdXrefs.isEmpty() || !deletedXrefs.isEmpty())) {
        report.getAddedXrefs().addAll(createdXrefs);
        report.getRemovedXrefs().addAll(deletedXrefs);
    }

    sortedXrefs.clear();
    sortedUniprotXrefs.clear();

    return report;
}

From source file:org.apache.ambari.eventdb.webservice.WorkflowJsonService.java

private static Set<Long> getXPoints(List<TaskAttempt> taskAttempts, long submitTimeX, long finishTimeX) {
    TreeSet<Long> xPoints = new TreeSet<Long>();
    TreeSet<TaskAttempt> sortedAttempts = new TreeSet<TaskAttempt>(new Comparator<TaskAttempt>() {
        @Override/*from   ww w .j  a v  a  2s  .c  om*/
        public int compare(TaskAttempt t1, TaskAttempt t2) {
            if (t1.getStartTime() < t2.getStartTime())
                return -1;
            else if (t1.getStartTime() > t2.getStartTime())
                return 1;
            return t1.getTaskAttemptId().compareTo(t2.getTaskAttemptId());
        }
    });
    sortedAttempts.addAll(taskAttempts);
    getXPoints(sortedAttempts, xPoints);
    xPoints.add(submitTimeX);
    xPoints.add(finishTimeX);
    return xPoints;
}

From source file:net.spfbl.whois.SubnetIPv4.java

protected static synchronized TreeSet<Subnet> getSubnetSet() {
    TreeSet<Subnet> subnetSet = new TreeSet<Subnet>();
    subnetSet.addAll(MAP.values());
    return subnetSet;
}

From source file:net.spfbl.core.Client.java

public synchronized static TreeSet<Client> getSet() {
    TreeSet<Client> clientSet = new TreeSet<Client>();
    clientSet.addAll(MAP.values());
    return clientSet;
}

From source file:net.spfbl.dns.QueryDNS.java

public static synchronized TreeSet<Zone> getValues() {
    TreeSet<Zone> serverSet = new TreeSet<Zone>();
    serverSet.addAll(MAP.values());
    return serverSet;
}

From source file:jetbrains.exodus.env.Reflect.java

private static void dumpCounts(@NotNull final String message, @NotNull final IntHashMap<Integer> counts) {
    System.out.println();//from ww w  .  ja  va 2 s.c o  m
    System.out.println(message);
    final TreeSet<Integer> sortedKeys = new TreeSet<>(new Comparator<Integer>() {
        @Override
        public int compare(Integer o1, Integer o2) {
            final Integer count1 = counts.get(o1);
            final Integer count2 = counts.get(o2);
            if (count1 < count2) {
                return 1;
            }
            if (count2 < count1) {
                return -1;
            }
            return 0;
        }
    });
    sortedKeys.addAll(counts.keySet());
    for (final Integer key : sortedKeys) {
        System.out.print(key + ":" + counts.get(key) + ' ');
    }
    System.out.println();
}

From source file:org.marketcetera.util.ws.types.TypeTest.java

private static <V> TreeSet<V> toTreeSet(List<V> in, Comparator<? super V> comparator) {
    TreeSet<V> out;
    if (comparator == null) {
        out = new TreeSet<V>();
    } else {//ww  w.  java2s  .c  o m
        out = new TreeSet<V>(comparator);
    }
    out.addAll(in);
    return out;
}

From source file:com.ery.hadoop.mrddx.client.MRJOBClient.java

/**
 * ?//from  w w  w . j  a v  a 2 s . c o  m
 * 
 * @param paraMap ??
 */
private void printParameter(Map<String, String> paraMap) {
    MRLog.systemOut("??:");
    TreeSet<String> ts = new TreeSet<String>();
    ts.addAll(paraMap.keySet());
    Iterator<String> i = ts.iterator();
    while (i.hasNext()) {
        String key = i.next();
        System.out.println(key + ":" + paraMap.get(key));
    }
}