List of usage examples for java.util TreeSet iterator
public Iterator<E> iterator()
From source file:org.apache.jmeter.protocol.http.parser.TestHTMLParser.java
private static void filetest(HTMLParser p, String file, String url, String resultFile, Collection<URLString> c, boolean orderMatters, // Does the order matter? String userAgent) throws Exception { String parserName = p.getClass().getName().substring("org.apache.jmeter.protocol.http.parser.".length()); String fname = file.substring(file.indexOf('/') + 1); log.debug("file " + file); File f = findTestFile(file);//w ww.jav a 2s . c o m byte[] buffer = new byte[(int) f.length()]; InputStream is = null; try { is = new FileInputStream(f); int len = is.read(buffer); assertEquals(len, buffer.length); } finally { IOUtils.closeQuietly(is); } Iterator<URL> result; if (c == null) { result = p.getEmbeddedResourceURLs(userAgent, buffer, new URL(url), System.getProperty("file.encoding")); } else { result = p.getEmbeddedResourceURLs(userAgent, buffer, new URL(url), c, System.getProperty("file.encoding")); } /* * TODO: Exact ordering is only required for some tests; change the * comparison to do a set compare where necessary. */ Iterator<String> expected; if (orderMatters) { expected = getFile(resultFile).iterator(); } else { // Convert both to Sets expected = new TreeSet<>(getFile(resultFile)).iterator(); TreeSet<URL> temp = new TreeSet<>(new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { return (o1.toString().compareTo(o2.toString())); } }); while (result.hasNext()) { temp.add(result.next()); } result = temp.iterator(); } while (expected.hasNext()) { Object next = expected.next(); assertTrue(userAgent + "::" + fname + "::" + parserName + "::Expecting another result " + next, result.hasNext()); try { assertEquals(userAgent + "::" + fname + "::" + parserName + "(next)", next, result.next().toString()); } catch (ClassCastException e) { fail(userAgent + "::" + fname + "::" + parserName + "::Expected URL, but got " + e.toString()); } } assertFalse(userAgent + "::" + fname + "::" + parserName + "::Should have reached the end of the results", result.hasNext()); }
From source file:org.alfresco.web.forms.xforms.SchemaUtil.java
public static TreeMap<String, TreeSet<XSTypeDefinition>> buildTypeTree(final XSModel schema) { final TreeMap<String, TreeSet<XSTypeDefinition>> result = new TreeMap<String, TreeSet<XSTypeDefinition>>(); if (LOGGER.isDebugEnabled()) LOGGER.debug("buildTypeTree " + schema); // build the type tree for complex types final XSNamedMap types = schema.getComponents(XSConstants.TYPE_DEFINITION); for (int i = 0; i < types.getLength(); i++) { final XSTypeDefinition t = (XSTypeDefinition) types.item(i); if (t.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { final XSComplexTypeDefinition type = (XSComplexTypeDefinition) t; SchemaUtil.buildTypeTree(type, new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER), result); }// ww w . j a va2s. c o m } // build the type tree for simple types for (int i = 0; i < types.getLength(); i++) { final XSTypeDefinition t = (XSTypeDefinition) types.item(i); if (t.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { SchemaUtil.buildTypeTree((XSSimpleTypeDefinition) t, new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER), result); } } // print out type hierarchy for debugging purposes if (LOGGER.isDebugEnabled()) { for (String typeName : result.keySet()) { TreeSet<XSTypeDefinition> descendents = result.get(typeName); LOGGER.debug(">>>> for " + typeName + " Descendants=\n "); Iterator<XSTypeDefinition> it = descendents.iterator(); while (it.hasNext()) { XSTypeDefinition desc = it.next(); LOGGER.debug(" " + desc.getName()); } } } return result; }
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 . j ava 2s.co 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 ww 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:gobblin.util.ConfigUtils.java
/** * Finds a list of properties whose keys are complete prefix of other keys. This function is * meant to be used during conversion from Properties to typesafe Config as the latter does not * support this scenario.//from w w w .j a v a2 s . c o m * @param properties the Properties collection to inspect * @param keyPrefix an optional key prefix which limits which properties are inspected. * */ public static Set<String> findFullPrefixKeys(Properties properties, Optional<String> keyPrefix) { TreeSet<String> propNames = new TreeSet<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String entryKey = entry.getKey().toString(); if (StringUtils.startsWith(entryKey, keyPrefix.or(StringUtils.EMPTY))) { propNames.add(entryKey); } } Set<String> result = new HashSet<>(); String lastKey = null; Iterator<String> sortedKeysIter = propNames.iterator(); while (sortedKeysIter.hasNext()) { String propName = sortedKeysIter.next(); if (null != lastKey && propName.startsWith(lastKey + ".")) { result.add(lastKey); } lastKey = propName; } return result; }
From source file:DecorateMutationsSNP.java
/** * The procedure creates a .txt file containing the information about the SNP mutations in the extant units * The first row represents the position of each mutation that is a double value in the interval (0,1) * The other rows represent the leave nodes as a matrix of 0 and 1 indicating the absence/presence of the corresponding mutation * @param wholePath path of the directory where the output file is stored * @param arg instance of the class PopulationARG that represents the ARG of a single population (in this case and actual population) * @see PopulationARG/* w w w . ja va2 s . c o m*/ */ public static void createSNP_TxtFile(String wholePath, PopulationARG arg) { Writer writer = null; File file = new File("" + wholePath); try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8")); TreeSet<Double> posMutations = GenerateAdmixturePopulations.getAllMutations(); //System.out.println("Creating file SNPs for population "+arg.getId_pop()); //System.out.println("# of all mutations in all populations "+posMutations.size()); writer.write("Population " + arg.getId_pop() + "\n"); writer.write("Number of extant units (rows): " + arg.getExtantUnits() + "\n"); writer.write("Number of SNPs for each extant unit (columns): " + posMutations.size() + "\n\n"); Iterator<Double> it_posMuts = posMutations.iterator(); Double position; while (it_posMuts.hasNext()) { position = it_posMuts.next(); String troncato = String.format("%.4f", position); writer.write(troncato + " "); } writer.write("\n\n"); //For each leave print a row representing the absence or presence of SNP mutations for (int i = 0; i < arg.getExtantUnits(); i++) { it_posMuts = posMutations.iterator(); while (it_posMuts.hasNext()) { position = it_posMuts.next(); //check if the arg has the mutation if (arg.getMutationSet().containsKey(position)) { //if yes then check if the leaf has the mutation //Mutation mut = arg.getMutationSet().get(position); TreeSet<Double> muts_set = arg.getNodeSet().get(i).getMutation_set(); if (muts_set.contains(position)) writer.write("1 "); else writer.write("0 "); } else writer.write("0 "); } writer.write("\n"); } writer.close(); } //fine try catch (IOException ex) { // report } }
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();/* w w w. 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:com.ery.hadoop.mrddx.client.MRJOBClient.java
/** * ?//from w ww . j a va 2 s. c om * * @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)); } }
From source file:org.jboss.dashboard.ui.config.treeNodes.FactoryFolderNode.java
protected List listChildren() { List list = new ArrayList(); Map mappings = getMappings(); TreeSet keys = new TreeSet(mappings.keySet()); for (Iterator iterator = keys.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); Object val = mappings.get(key); list.add(getNewSubNode(key, val)); }/*from w ww. j av a 2 s.co m*/ Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { if (o1.getClass().equals(o2.getClass())) { FactoryNode node1 = (FactoryNode) o1; FactoryNode node2 = (FactoryNode) o2; return node1.getNodeName().compareTo(node2.getNodeName()); } return o2.getClass().getName().compareTo(o1.getClass().getName()); } }); return list; }
From source file:org.unitime.timetable.test.StudentSectioningTest.java
private static String getInstructorIds(Class_ clazz) { if (!clazz.isDisplayInstructor().booleanValue()) return null; String ret = null;//from w w w . j av a2 s . co m TreeSet ts = new TreeSet(clazz.getClassInstructors()); for (Iterator i = ts.iterator(); i.hasNext();) { ClassInstructor ci = (ClassInstructor) i.next(); if (!ci.isLead().booleanValue()) continue; if (ret == null) ret = ci.getInstructor().getUniqueId().toString(); else ret += ":" + ci.getInstructor().getUniqueId().toString(); } return ret; }