List of usage examples for java.util TreeMap size
int size
To view the source code for java.util TreeMap size.
Click Source Link
From source file:org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetricCacheEntryFactory.java
private void updateExistingMetricValues(TimelineMetrics existingMetrics, Long requestedStartTime, Long requestedEndTime, boolean removeAll) { for (TimelineMetric existingMetric : existingMetrics.getMetrics()) { if (removeAll) { existingMetric.setMetricValues(new TreeMap<Long, Double>()); } else {/*from ww w. ja va2 s . co m*/ TreeMap<Long, Double> existingMetricValues = existingMetric.getMetricValues(); LOG.trace( "Existing metric: " + existingMetric.getMetricName() + " # " + existingMetricValues.size()); // Retain only the values that are within the [requestStartTime, requestedEndTime] window existingMetricValues.headMap(requestedStartTime, false).clear(); existingMetricValues.tailMap(requestedEndTime, false).clear(); } } }
From source file:kmi.taa.core.Crawler.java
public void crawlAll(TreeMap<Integer, String> targetUrls, String service, String proxy, String otfile) { SortedSet<Integer> results = Collections.synchronizedSortedSet(new TreeSet<Integer>()); ExecutorService pool = Executors.newFixedThreadPool(100); int howManyUrls = targetUrls.size(); System.out.println("total " + howManyUrls + " to be processed"); List<String> output = Collections.synchronizedList(new ArrayList<String>()); for (Integer targetId : targetUrls.navigableKeySet()) { String uri = targetUrls.get(targetId); pool.execute(new Explorer(targetId, uri, service, proxy, results, otfile, output)); }// w w w . j a v a 2s .c o m pool.shutdown(); while (results.size() < howManyUrls) { System.out.println("already processed " + results.size() + " subject links"); try { Thread.sleep(1000); } catch (InterruptedException e) { log.error("crawlAll error", e); } } resultToFile(output, otfile); System.out.println("already processed " + results.size() + " subject links"); }
From source file:net.tradelib.core.Series.java
public Series toDaily(double identity, BinaryOperator<Double> accumulator) { TreeMap<LocalDateTime, Integer> newIndex = buildDailyIndex(); Series result = new Series(); int numUnique = newIndex.size(); result.index = new ArrayList<LocalDateTime>(numUnique); result.data = new ArrayList<List<Double>>(data.size()); for (int ii = 0; ii < data.size(); ++ii) { result.data.add(new ArrayList<Double>(newIndex.size())); }/*w w w. j a va 2 s .c o m*/ int currentIndex = 0; Iterator<Map.Entry<LocalDateTime, Integer>> iter = newIndex.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<LocalDateTime, Integer> entry = iter.next(); result.append(entry.getKey(), 0.0); int lastIndex = result.size() - 1; for (int jj = 0; jj < data.size(); ++jj) { result.set(lastIndex, data.get(jj).subList(currentIndex, currentIndex + entry.getValue()).stream() .reduce(identity, accumulator)); } currentIndex += entry.getValue(); // result.append(entry.getKey(), 0.0); // int lastIndex = result.size() - 1; // for(int ii = 0; ii < entry.getValue(); ++ii, ++currentIndex) { // for(int jj = 0; jj < data.size(); ++jj) { // result.set(lastIndex, jj, result.get(lastIndex, jj) + get(currentIndex, jj)); // } // } } if (columnNames != null) { result.columnNames = new HashMap<String, Integer>(columnNames); } return result; }
From source file:checkdb.CheckDb.java
private void makeChannelIndexTable() throws SQLException { Pattern ifoSubsysPat = Pattern.compile("(^.+):((.+?)[_-])?"); for (Entry<String, TreeMap<String, ChanStat>> csl : chanstats.entrySet()) { ChanIndexInfo cii = new ChanIndexInfo(); String cname = csl.getKey(); cii.setName(cname);/*from w w w .jav a2 s. c o m*/ TreeMap<String, ChanStat> serverList = csl.getValue(); int n = serverList.size(); cii.setnServers(n); Matcher ifoSubsys = ifoSubsysPat.matcher(cname); if (ifoSubsys.find()) { cii.setIfo(ifoSubsys.group(1)); String subsys = ifoSubsys.group(3); subsys = subsys == null ? "" : subsys; cii.setSubsys(subsys); } else { cii.setIfo(""); cii.setSubsys(""); } float minRawRate = Float.MAX_VALUE; float maxRawRate = Float.MIN_VALUE; float minRdsRate = Float.MAX_VALUE; float maxRdsRate = Float.MIN_VALUE; boolean hasRaw = false; boolean hasRds = false; boolean hasOnline = false; boolean hasMtrends = false; boolean hasStrends = false; boolean hasTstpnt = false; boolean hasStatic = false; String cisAvail = " "; for (Entry<String, ChanStat> srv : serverList.entrySet()) { ChanStat cs = srv.getValue(); minRawRate = Math.min(minRawRate, cs.getMinRawRate()); maxRawRate = Math.max(maxRawRate, cs.getMaxRawRate()); maxRdsRate = Math.max(maxRdsRate, cs.getMaxRdsRate()); minRdsRate = Math.min(minRdsRate, cs.getMinRdsRate()); hasRaw |= cs.hasRaw(); hasRds |= cs.hasRds(); hasMtrends |= cs.hasMtrends(); hasStrends |= cs.hasStrend(); hasStatic |= cs.hasStatic(); hasOnline |= cs.hasOnline(); String cis = cs.getCisAvail(); if (cis.equalsIgnoreCase("d")) { cisAvail = cis; } else if (!cisAvail.equalsIgnoreCase("d") && cis.equalsIgnoreCase("a")) { cisAvail = cis; } } minRawRate = minRawRate == Float.MAX_VALUE ? 0 : minRawRate; cii.setMinRawRate(minRawRate); maxRawRate = maxRawRate == Float.MIN_VALUE ? 0 : maxRawRate; cii.setMaxRawRate(maxRawRate); minRdsRate = minRdsRate == Float.MAX_VALUE ? 0 : minRdsRate; cii.setMinRdsRate(minRdsRate); maxRdsRate = maxRdsRate == Float.MIN_VALUE ? 0 : maxRdsRate; cii.setMaxRdsRate(maxRdsRate); cii.setCisAvail(cisAvail); cii.setHasMtrends(hasMtrends); cii.setHasRaw(hasRaw); cii.setHasRds(hasRds); cii.setHasStrends(hasStrends); cii.setHasStatic(hasStatic); cii.setHasTestpoint(hasTstpnt); cii.setHasOnline(hasOnline); cidx.insertNewBulk(cii); } cidx.insertNewBulk(null); // flush any remaining }
From source file:org.mda.bcb.tcgagsdata.create.ProcessFile.java
protected void writeCombinedFiles(TreeMap<String, Integer> theGeneEqList) throws IOException { File outputDir = getOutputDir(); TcgaGSData.printWithFlag("mGeneEqMap.size()=" + theGeneEqList.size()); TcgaGSData.printWithFlag("mSampleList.size()=" + mSampleList.size()); // gene lines HashMap<String, ArrayList<String>> hashprefixToGeneList = new HashMap<>(); for (String geneEq : theGeneEqList.keySet()) { String md5prefix = DigestUtils.md5Hex(geneEq).substring(0, 2); ArrayList<String> genesublist = hashprefixToGeneList.get(md5prefix); if (null == genesublist) { genesublist = new ArrayList<>(); }/*w w w . j a v a 2s . c om*/ genesublist.add(geneEq); hashprefixToGeneList.put(md5prefix, genesublist); } for (String md5prefix : hashprefixToGeneList.keySet()) { ArrayList<String> genesublist = hashprefixToGeneList.get(md5prefix); writeToMD5File(md5prefix, theGeneEqList, genesublist); } }
From source file:com.act.lcms.db.analysis.AnalysisHelper.java
/** * This function scores the various metlin ions from different standard ion results, sorts them and picks the * best ion. This is done by adding up the indexed positions of the ion in each sorted entry of the list of * standard ion results. Since the entries in the standard ion results are sorted, the lower magnitude summation ions * are better than the larger magnitude summations. Then, we add another feature, in this case, the normalized SNR/maxSNR * but multiplying the positional score with the normalized SNR. The exact calculation is as follows: * score = positional_score * (1 - SNR(i)/maxSNR). We have to do the (1 - rel_snr) since we choose the lowest score, * so if the rel_snr is huge (ie a good signal), the overall magnitude of score will reduce, which makes that a better * ranking for the ion. We then do a post filtering on these scores based on if we have only positive/negative scans * from the scan files which exist in the context of the caller. * @param standardIonResults The list of standard ion results * @param curatedMetlinIons A map from standard ion result to the best curated ion that was manual inputted. * @param areOtherPositiveModeScansAvailable This boolean is used to post filter and pick a positive metlin ion if and * only if positive ion mode scans are available. * @param areOtherNegativeModeScansAvailable This boolean is used to post filter and pick a negative metlin ion if and * only if negative ion mode scans are available. * @return The best metlin ion or null if none can be found */// w w w .j av a 2 s .co m public static String scoreAndReturnBestMetlinIonFromStandardIonResults( List<StandardIonResult> standardIonResults, Map<StandardIonResult, String> curatedMetlinIons, boolean areOtherPositiveModeScansAvailable, boolean areOtherNegativeModeScansAvailable) { if (standardIonResults == null) { return null; } // We find the maximum SNR values for each standard ion result so that we can normalize individual SNR scores // during scoring. HashMap<StandardIonResult, Double> resultToMaxSNR = new HashMap<>(); for (StandardIonResult result : standardIonResults) { Double maxSNR = 0.0d; for (Map.Entry<String, XZ> resultoDoublePair : result.getAnalysisResults().entrySet()) { if (resultoDoublePair.getValue().getIntensity() > maxSNR) { maxSNR = resultoDoublePair.getValue().getIntensity(); } } resultToMaxSNR.put(result, maxSNR); } Map<String, Double> metlinScore = new HashMap<>(); Set<String> ions = standardIonResults.get(0).getAnalysisResults().keySet(); // For each ion, iterate through all the ion results to find the position of that ion in each result set (since the // ions are sorted) and then multiply that by a normalized value of the SNR. for (String ion : ions) { for (StandardIonResult result : standardIonResults) { Integer counter = 0; for (String localIon : result.getAnalysisResults().keySet()) { counter++; if (localIon.equals(ion)) { Double ionScore = metlinScore.get(ion); if (ionScore == null) { // Normalize the sample's SNR by dividing it by the maxSNR. Then we multiple a variant of it to the counter // score so that if the total magnitude of the score is lower, the ion is ranked higher. ionScore = (1.0 * counter) * (1 - (result.getAnalysisResults().get(ion).getIntensity() / resultToMaxSNR.get(result))); } else { ionScore += (1.0 * counter) * (1 - (result.getAnalysisResults().get(ion).getIntensity() / resultToMaxSNR.get(result))); } metlinScore.put(ion, ionScore); break; } } } } for (Map.Entry<StandardIonResult, String> resultToIon : curatedMetlinIons.entrySet()) { // Override all the scores of the manually curated standard ion result and set them to the highest rank. // Ideally, the user has been consistent for the best metlin ion across similar standard ion results, so // tie breakers will not happen. If a tie happen, it is broken arbitrarily. metlinScore.put(resultToIon.getValue(), MANUAL_OVERRIDE_BEST_SCORE); } TreeMap<Double, List<String>> sortedScores = new TreeMap<>(); for (String ion : metlinScore.keySet()) { if (MS1.getIonModeOfIon(ion) != null) { if ((MS1.getIonModeOfIon(ion).equals(MS1.IonMode.POS) && areOtherPositiveModeScansAvailable) || (MS1.getIonModeOfIon(ion).equals(MS1.IonMode.NEG) && areOtherNegativeModeScansAvailable)) { List<String> ionBucket = sortedScores.get(metlinScore.get(ion)); if (ionBucket == null) { ionBucket = new ArrayList<>(); } ionBucket.add(ion); sortedScores.put(metlinScore.get(ion), ionBucket); } } } if (sortedScores.size() == 0) { LOGGER.error( "Could not find any ions corresponding to the positive and negative scan mode conditionals"); return null; } else { List<String> topMetlinIons = sortedScores.get(sortedScores.keySet().iterator().next()); // In cases of a tie breaker, simply choose the first ion. return topMetlinIons.get(0); } }
From source file:org.cloudata.core.client.Row.java
@Override public void write(DataOutput out) throws IOException { key.write(out);/* w w w. ja va 2 s. com*/ out.writeInt(cells.size()); for (Map.Entry<String, TreeMap<Cell.Key, Cell>> entry : cells.entrySet()) { String columnName = entry.getKey(); CWritableUtils.writeString(out, columnName); TreeMap<Cell.Key, Cell> columnCells = entry.getValue(); int columnCellsSize = columnCells == null ? 0 : columnCells.size(); out.writeInt(columnCellsSize); if (columnCellsSize > 0) { for (Cell eachCell : columnCells.values()) { //System.out.println(columnName + ">" + eachCell.getKey() + ">" + eachCell.getValueAsString()); eachCell.write(out); } } } }
From source file:io.mapzone.arena.analytics.graph.ui.FeaturePropertySelectorUI.java
private void fill() { if (combo != null && !combo.isDisposed() && featureSource != null) { final Collection<PropertyDescriptor> schemaDescriptors = featureSource.getSchema().getDescriptors(); final GeometryDescriptor geometryDescriptor = featureSource.getSchema().getGeometryDescriptor(); final TreeMap<String, PropertyDescriptor> properties = Maps.newTreeMap(); for (PropertyDescriptor descriptor : schemaDescriptors) { if (geometryDescriptor == null || !geometryDescriptor.equals(descriptor)) { properties.put(descriptor.getName().getLocalPart(), descriptor); }/*from ww w .j a v a 2 s . co m*/ } final List<String> columns = Lists.newArrayList(); columns.addAll(properties.keySet()); combo.setItems(columns.toArray(new String[properties.size()])); combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { onSelect.accept(properties.get(columns.get(combo.getSelectionIndex()))); } }); combo.getParent().layout(); } }
From source file:tor.Consensus.java
/** * Return the routers with all of the supplied flags and the specified exitPort, optionally excluding bad exits. * See https://consensus-health.torproject.org for a list of known flags. * * @param flags the desired flags (case-sensitive) * @param exitPort the desired exit port in the router's exit policy (or 0 to ignore exit policies) * @param excludeBadExits exclude routers with the BadExit flags (these are considered unreliable for some purposes) * @return a random router with the specified flags *//*from www.j ava 2 s .c o m*/ public OnionRouter getRandomORWithFlag(String[] flags, int exitPort, Boolean excludeBadExits) { TreeMap<String, OnionRouter> map = getORsWithFlag(flags, excludeBadExits); OnionRouter ors[] = map.values().toArray(new OnionRouter[map.size()]); boolean acceptsExitPort = false; int idx = TorCrypto.rnd.nextInt(ors.length); // ignore exitPort 0 if (exitPort != 0) { // iterate through the routers until we find one that accepts the desired exitPort do { idx = TorCrypto.rnd.nextInt(ors.length); acceptsExitPort = ors[idx].acceptsIPv4ExitPort(exitPort); } while (!acceptsExitPort); } return ors[idx]; }
From source file:org.xwiki.contrib.mailarchive.timeline.internal.TimeLineGenerator.java
private String printEvents(TreeMap<Long, TimeLineEvent> sortedEvents) { DefaultWikiPrinter printer = new DefaultWikiPrinter(); timelineWriter.setWikiPrinter(printer); timelineWriter.print(sortedEvents);//from w w w.j a v a 2 s . c om logger.debug("Loaded " + sortedEvents.size() + " into Timeline feed"); logger.debug("Timeline data {}", printer.toString()); return printer.toString(); }