List of usage examples for java.util TreeSet TreeSet
public TreeSet()
From source file:api.util.JsonObjectMap.java
@Override public Set<Entry<String, T>> entrySet() { Iterator it = object.keys();//from w ww . j a v a2s .co m TreeSet set = new TreeSet(); while (it.hasNext()) { final String key = (String) it.next(); set.add(new Entry<String, Object>() { @Override public String getKey() { return key; } @Override public Object getValue() { return get(key); } @Override public Object setValue(Object value) { throw new UnsupportedOperationException(); } }); } return set; }
From source file:com.espertech.esper.schedule.TestScheduleSpec.java
public void testValidate() { // Test all units missing EnumMap<ScheduleUnit, SortedSet<Integer>> unitValues = new EnumMap<ScheduleUnit, SortedSet<Integer>>( ScheduleUnit.class); assertInvalid(unitValues);/*from w w w .j a va2 s . c o m*/ // Test one unit missing unitValues = (new ScheduleSpec()).getUnitValues(); unitValues.remove(ScheduleUnit.HOURS); assertInvalid(unitValues); // Test all units are wildcards unitValues = (new ScheduleSpec()).getUnitValues(); new ScheduleSpec(unitValues, null, null, null); // Test invalid value in month SortedSet<Integer> values = new TreeSet<Integer>(); values.add(0); unitValues.put(ScheduleUnit.MONTHS, values); assertInvalid(unitValues); // Test valid value in month values = new TreeSet<Integer>(); values.add(1); values.add(5); unitValues.put(ScheduleUnit.MONTHS, values); new ScheduleSpec(unitValues, null, null, null); }
From source file:edu.uiowa.icts.bluebutton.json.view.EncountersMetaFinder.java
public String getOrganizations() { TreeSet<String> orgSet = new TreeSet<String>(); for (Encounter e : this.list) { if (e.getLocation() != null && e.getLocation().getOrganization() != null) { orgSet.add(e.getLocation().getOrganization()); }// w w w .j a v a2 s . co m } if (orgSet.size() > 0) { return StringUtils.join(orgSet, ", "); } return null; }
From source file:fi.smaa.libror.PerformanceMatrix.java
private void initializeLevels(RealMatrix perfMatrix) { levels = new RealVector[perfMatrix.getColumnDimension()]; for (int i = 0; i < levels.length; i++) { Set<Double> levelsSet = new TreeSet<Double>(); for (double d : perfMatrix.getColumn(i)) { levelsSet.add(d);/* ww w . jav a 2 s . c o m*/ } RealVector lvl = new ArrayRealVector(levelsSet.toArray(new Double[0])); levels[i] = lvl; } }
From source file:com.glaf.core.util.AnnotationUtils.java
public static Collection<String> findMapper(String packagePrefix) { AnnotationDB db = getAnnotationDB(packagePrefix); Map<String, Set<String>> annotationIndex = db.getAnnotationIndex(); Set<String> entities = annotationIndex.get("org.springframework.stereotype.Component"); Collection<String> sortSet = new TreeSet<String>(); if (entities != null && !entities.isEmpty()) { for (String str : entities) { if (packagePrefix != null && str.contains(packagePrefix) && StringUtils.contains(str, ".mapper.")) { sortSet.add(str);//from w ww . j a v a 2s . c o m } } } return sortSet; }
From source file:com.collective.celos.servlet.JSONWorkflowListServlet.java
ObjectNode createJSONObject(WorkflowConfiguration cfg) { // Make sure the IDs are sorted SortedSet<String> ids = new TreeSet<String>(); for (Workflow wf : cfg.getWorkflows()) { ids.add(wf.getID().toString());//from ww w.j a v a 2 s .co m } ArrayNode list = Util.MAPPER.createArrayNode(); for (String id : ids) { list.add(id); } ObjectNode object = Util.MAPPER.createObjectNode(); object.put(CelosClient.IDS_PARAM, list); return object; }
From source file:net.sf.jabref.importer.TextAnalyzer.java
private void guessBibtexFields(String text) { TreeSet<Substring> usedParts = new TreeSet<>(); text = " " + text + " "; String[] split;/*w w w . j a va2 s. c om*/ // Look for the year: String year = null; String yearRx = "(\\s|\\()\\d\\d\\d\\d(\\.|,|\\))"; String[] cand = getMatches(text, yearRx); if (cand.length == 1) { // Only one four-digit number, so we guess that is the year. year = clean(cand[0]); int pos = text.indexOf(year); usedParts.add(new Substring("year", pos, pos + year.length())); LOGGER.debug("Guessing 'year': '" + year + "'"); } else if (cand.length > 1) { // More than one four-digit numbers, so we look for one giving a reasonable year: int good = -1; int yearFound = -1; for (int i = 0; i < cand.length; i++) { int number = Integer.parseInt(cand[i].trim()); if (number == yearFound) { continue; } if (number < 2500) { if (good == -1) { good = i; yearFound = number; } else { // More than one found. Be a bit more specific. if ((yearFound < FUTURE_YEAR) && (number < FUTURE_YEAR)) { good = -1; break; // Give up, both seem good enough. } else if ((yearFound >= FUTURE_YEAR) && (number < FUTURE_YEAR)) { good = i; yearFound = number; } } } } if (good >= 0) { year = clean(cand[good]); int pos = text.indexOf(year); usedParts.add(new Substring("year", pos, pos + year.length())); LOGGER.debug("Guessing 'year': '" + year + "'"); } } // Look for Pages: String pages; String pagesRx = "\\s(\\d{1,4})( ??)-( ??)(\\d{1,4})(\\.|,|\\s)"; cand = getMatches(text, pagesRx); if (cand.length == 1) { pages = clean(cand[0].replaceAll("-|( - )", "--")); int pos = text.indexOf(cand[0]); usedParts.add(new Substring("pages", pos, pos + year.length())); LOGGER.debug("Guessing 'pages': '" + pages + "'"); } else if (cand.length > 1) { int found = -1; for (int i = 0; i < cand.length; i++) { split = clean(cand[i].replaceAll("\\s", "")).split("-"); // Util.pr("Pg: "+pages); int first = Integer.parseInt(split[0]); int second = Integer.parseInt(split[1]); if ((second - first) > 3) { found = i; break; } } if (found >= 0) { pages = clean(cand[found].replaceAll("-|( - )", "--")); int pos = text.indexOf(cand[found]); LOGGER.debug("Guessing 'pages': '" + pages + "'"); usedParts.add(new Substring("pages", pos, pos + pages.length())); } } //String journalRx = "(\\.|\\n)\\s??([a-zA-Z\\. ]{8,30}+)((vol\\.|Vol\\.|Volume|volume))??(.??)(\\d{1,3})(\\.|,|\\s)"; String journal; String volume; String journalRx = "(,|\\.|\\n)\\s??([a-zA-Z\\. ]{8,30}+)((.){0,2})((vol\\.|Vol\\.|Volume|volume))??\\s??(\\d{1,3})(\\.|,|\\s|:)"; cand = getMatches(text, journalRx); if (cand.length > 0) { //Util.pr("guessing 'journal': '" + cand[0] + "'"); cand[0] = cand[0].trim(); int pos = cand[0].lastIndexOf(' '); if (pos > 0) { volume = clean(cand[0].substring(pos + 1)); LOGGER.debug("Guessing 'volume': '" + volume + "'"); journal = clean(cand[0].substring(0, pos)); //Util.pr("guessing 'journal': '" + journal + "'"); pos = journal.lastIndexOf(' '); if (pos > 0) { String last = journal.substring(pos + 1).toLowerCase(); if ("volume".equals(last) || "vol".equals(last) || "v".equals(last)) { journal = clean(journal.substring(0, pos)); } } pos = text.indexOf(journal); usedParts.add(new Substring("journal", pos, pos + journal.length())); LOGGER.debug("Guessing 'journal': '" + journal + "'"); } //Util.pr("Journal? '"+cand[0]+"'"); } else { // No journal found. Maybe the year precedes the volume? Try another regexp: } // Then try to find title and authors. Substring ss; Vector<String> free = new Vector<>(); int piv = 0; for (Substring usedPart : usedParts) { ss = usedPart; if ((ss.begin() - piv) > 10) { LOGGER.debug("... " + text.substring(piv, ss.begin())); free.add(clean(text.substring(piv, ss.begin()))); } piv = ss.end(); } if ((text.length() - piv) > 10) { free.add(clean(text.substring(piv))); } LOGGER.debug("Free parts:"); for (String s : free) { LOGGER.debug(": '" + s + "'"); } }
From source file:DecorateMutationsSNP.java
/** * The procedure computes for each edge of the ARG the number of mutations occurred in that period of time (length of the edge) by means of Poisson and Normal distributions * @param mu real value that is SNP mutation rate * @param arg instance of the class PopulationARG representing the ARG of a single population * @throws ErrorTimesInputFileException this exception is thrown if there is an inconsistency in time parameters setting * @see PopulationARG// www . j a v a 2 s . co m */ public static void decoratingWithMutations(double mu, PopulationARG arg) throws ErrorTimesInputFileException { //For each leaf of arg create a set of mutations in the node for (int j = 0; j < arg.getExtantUnits(); j++) { arg.getNodeSet().get(j).setLeaf(true); arg.getNodeSet().get(j).setMutation_set(new TreeSet<Double>()); } Iterator<Integer> it_edges = arg.getGraphEdges().keySet().iterator(); double lamda = 0; //System.out.println("------- SNPs Decoration of Population "+arg.getId_pop()+" ------------ "); //For each edge in the ARG, compute the number of mutations and decorate the solids while (it_edges.hasNext()) { Integer keyE = it_edges.next(); if (arg.getGraphEdges().get(keyE).getId_fath() != -1) { double density = arg.getGraphEdges().get(keyE).computeDensity(); double time = arg.getGraphEdges().get(keyE).getTime(); //*** if time is negative then throw the exception that //there is probably an error in how the time parameters are specified in the input file ***// if (time <= 0) { throw new ErrorTimesInputFileException(); } //System.out.println("Time: "+arg.getGraphEdges().get(keyE).getTime()); double n = arg.getG() * density; double p = mu * arg.getN() * time; //******* Compute the # of mutations by Poisson Distribution ****** lamda = n * p; PoissonDistribution Prand = new PoissonDistribution(lamda); int randomPois = Prand.sample(); arg.getGraphEdges().get(keyE).setnMut(randomPois); if (randomPois == 0) GenerateAdmixturePopulations .setNum_edges_without_mut(GenerateAdmixturePopulations.getNum_edges_without_mut() + 1); else GenerateAdmixturePopulations.setNum_edges_more_than_one_mut( GenerateAdmixturePopulations.getNum_edges_more_than_one_mut() + 1); //For each mutation we assign a position for (int i = 0; i < arg.getGraphEdges().get(keyE).getnMut(); i++) { //maps the real solids in (0,1) in an interval (0,densityTotal) //by creating a new list of segments. double start = 0; ArrayList<Interval> tempSegs = new ArrayList<Interval>(); for (int j = 0; j < arg.getGraphEdges().get(keyE).getSegments().size(); j++) { double lengthInt = arg.getGraphEdges().get(keyE).getSegments().get(j).getEnd() - arg.getGraphEdges().get(keyE).getSegments().get(j).getStart(); tempSegs.add(new Interval(start, start + lengthInt)); start = start + lengthInt; } double x = Math.random() * arg.getGraphEdges().get(keyE).getDensity(); boolean found = false; int index = 0; while (!found && index < tempSegs.size()) { if (x >= tempSegs.get(index).getStart() && x < tempSegs.get(index).getEnd()) { found = true; } else { index++; } } double offset = x - tempSegs.get(index).getStart(); double posMutation = arg.getGraphEdges().get(keyE).getSegments().get(index).getStart() + offset; arg.getGraphEdges().get(keyE).getSegments().get(index).getPosMutations().add(posMutation); //add the mutation to the set of the all mutations GenerateAdmixturePopulations.getAllMutations().add(new Double(posMutation)); //Create the mutation object Mutation mut = new Mutation(); mut.setPositionID(posMutation); mut.setIDfather(arg.getGraphEdges().get(keyE).getId_fath()); mut.setIDson(arg.getGraphEdges().get(keyE).getId_son()); mut.setSegment(arg.getGraphEdges().get(keyE).getSegments().get(index)); mut.setLeaves(computeLeaves(arg.getGraphEdges().get(keyE).getId_son(), arg)); mut.setID_original_pop(arg.getId_pop()); arg.getSNPpositionsList().add(posMutation); arg.getMutationSet().put(posMutation, mut); GenerateAdmixturePopulations.getAllmutationSet().put(mut.getPositionID(), mut); //For each leaf (in the set), that has the mutation mut, add mut to the leaf TreeSet<Integer> leaves = mut.getLeaves(); Iterator<Integer> it_leaves = leaves.iterator(); while (it_leaves.hasNext()) { int l = it_leaves.next(); arg.getNodeSet().get(l).getMutation_set().add(mut.getPositionID()); } } //end of computing the exact position of each mutation } //end if the edge has a father } //end while for each edge of the ARG //System.out.println("------- End of SNPs Decoration of Population "+arg.getId_pop()+" ------------ "); }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.util.EvaluatorUtils.java
/** * Get the gold keyphrases from the file system. * By convention gold keyphrase files should have the same name as the document file. * Standard extension is .key, but something else can be specified in the corresponding parameter. * * @param metaData The DocumentMetaData annotation of this document. * @param goldSuffix The suffix of the gold standard file. * @param toLowerCase If gold keys should be lowercased or not. * * @return The set of gold keyphrases for this document. * @throws AnalysisEngineProcessException an analysis engine process exception *//*www .j a v a 2 s . c om*/ public static Set<String> getGoldKeyphrases(DocumentMetaData metaData, String goldSuffix, boolean toLowerCase) throws AnalysisEngineProcessException { Set<String> goldKeyphrases = new TreeSet<String>(); String uri = metaData.getDocumentUri(); URL keyUrl; try { keyUrl = URI.create(uri.substring(0, indexOfExtension(uri)) + goldSuffix).toURL(); List<String> lines = IOUtils.readLines(keyUrl.openStream(), "UTF-8"); for (String line : lines) { if (toLowerCase) { line = line.toLowerCase().trim(); } else { line = line.trim(); } if (line.length() > 0) { if (line.contains(";")) { for (String part : line.split(";")) { goldKeyphrases.add(part.trim()); } } else { goldKeyphrases.add(line); } } } return goldKeyphrases; } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
From source file:io.druid.query.search.FragmentSearchQuerySpec.java
@JsonCreator public FragmentSearchQuerySpec(@JsonProperty("values") List<String> values, @JsonProperty("caseSensitive") boolean caseSensitive) { this.values = values; this.caseSensitive = caseSensitive; Set<String> set = new TreeSet<>(); if (values != null) { for (String value : values) { set.add(value);/*from w w w . ja va2s .com*/ } } target = set.toArray(new String[set.size()]); }