List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:lisong_mechlab.view.graphs.SustainedDpsGraph.java
private TableXYDataset getSeries() { final Collection<Modifier> modifiers = loadout.getModifiers(); SortedMap<Weapon, List<Pair<Double, Double>>> data = new TreeMap<Weapon, List<Pair<Double, Double>>>( new Comparator<Weapon>() { @Override/*from w w w . j a v a2 s .co m*/ public int compare(Weapon aO1, Weapon aO2) { int comp = Double.compare(aO2.getRangeMax(modifiers), aO1.getRangeMax(modifiers)); if (comp == 0) return aO1.compareTo(aO2); return comp; } }); Double[] ranges = WeaponRanges.getRanges(loadout); for (double range : ranges) { Set<Entry<Weapon, Double>> damageDistributio = maxSustainedDPS.getWeaponRatios(range).entrySet(); for (Map.Entry<Weapon, Double> entry : damageDistributio) { final Weapon weapon = entry.getKey(); final double ratio = entry.getValue(); final double dps = weapon.getStat("d/s", modifiers); final double rangeEff = weapon.getRangeEffectivity(range, modifiers); if (!data.containsKey(weapon)) { data.put(weapon, new ArrayList<Pair<Double, Double>>()); } data.get(weapon).add(new Pair<Double, Double>(range, dps * ratio * rangeEff)); } } List<Weapon> orderedWeapons = new ArrayList<>(); DefaultTableXYDataset dataset = new DefaultTableXYDataset(); for (Map.Entry<Weapon, List<Pair<Double, Double>>> entry : data.entrySet()) { XYSeries series = new XYSeries(entry.getKey().getName(), true, false); for (Pair<Double, Double> pair : entry.getValue()) { series.add(pair.first, pair.second); } dataset.addSeries(series); orderedWeapons.add(entry.getKey()); } Collections.reverse(orderedWeapons); colours.updateColoursToMatch(orderedWeapons); return dataset; }
From source file:org.apache.sling.commons.metrics.internal.MetricWebConsolePlugin.java
private void addHistogramDetails(PrintWriter pw, SortedMap<String, Histogram> histograms) { if (histograms.isEmpty()) { return;//from www . j a v a 2s . co m } pw.println("<br>"); pw.println("<div class='table'>"); pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Histograms</div>"); pw.println("<table class='nicetable' id='data-histograms'>"); pw.println("<thead>"); pw.println("<tr>"); pw.println("<th class='header'>Name</th>"); pw.println("<th class='header'>Count</th>"); pw.println("<th class='header'>50%</th>"); pw.println("<th class='header'>Min</th>"); pw.println("<th class='header'>Max</th>"); pw.println("<th class='header'>Mean</th>"); pw.println("<th class='header'>StdDev</th>"); pw.println("<th class='header'>75%</th>"); pw.println("<th class='header'>95%</th>"); pw.println("<th class='header'>98%</th>"); pw.println("<th class='header'>99%</th>"); pw.println("<th class='header'>999%</th>"); pw.println("<th>Duration Unit</th>"); pw.println("</tr>"); pw.println("</thead>"); pw.println("<tbody>"); String rowClass = "odd"; for (Map.Entry<String, Histogram> e : histograms.entrySet()) { Histogram h = e.getValue(); Snapshot s = h.getSnapshot(); String name = e.getKey(); double durationFactor = 1.0 / timeUnit.durationFor(name).toNanos(1); String durationUnit = timeUnit.durationFor(name).toString().toLowerCase(Locale.US); pw.printf("<tr class='%s ui-state-default'>%n", rowClass); pw.printf("<td>%s</td>", name); pw.printf("<td>%d</td>", h.getCount()); pw.printf("<td>%f</td>", s.getMedian() * durationFactor); pw.printf("<td>%f</td>", s.getMin() * durationFactor); pw.printf("<td>%f</td>", s.getMax() * durationFactor); pw.printf("<td>%f</td>", s.getMean() * durationFactor); pw.printf("<td>%f</td>", s.getStdDev() * durationFactor); pw.printf("<td>%f</td>", s.get75thPercentile() * durationFactor); pw.printf("<td>%f</td>", s.get95thPercentile() * durationFactor); pw.printf("<td>%f</td>", s.get98thPercentile() * durationFactor); pw.printf("<td>%f</td>", s.get99thPercentile() * durationFactor); pw.printf("<td>%f</td>", s.get999thPercentile() * durationFactor); pw.printf("<td>%s</td>", durationUnit); pw.println("</tr>"); rowClass = "odd".equals(rowClass) ? "even" : "odd"; } pw.println("</tbody>"); pw.println("</table>"); pw.println("</div>"); }
From source file:de.dentrassi.pm.deb.aspect.internal.RepoBuilder.java
private void spoolOutDistRelease(final Distribution dist, final SortedMap<String, Checksums> checksums, final SpoolOutHandler handler) throws IOException { final StringWriter sw = new StringWriter(); final DistributionInformation info = dist.getInformation(); writeOptional(sw, "Origin", info.getOrigin()); writeOptional(sw, "Label", info.getLabel()); writeOptional(sw, "Suite", info.getSuite()); writeOptional(sw, "Version", info.getVersion()); writeOptional(sw, "Codename", info.getCodename()); write(sw, "Date", DATE_FORMAT.format(new Date())); write(sw, "Components", StringHelper.join(dist.getComponents().keySet(), " ")); write(sw, "Architectures", StringHelper.join(info.getArchitectures(), " ")); writeOptional(sw, "Description", info.getDescription()); {//from w ww. jav a2 s . c o m // create checksum fields final StringWriter md5 = new StringWriter(); final StringWriter sha1 = new StringWriter(); final StringWriter sha256 = new StringWriter(); final PrintWriter md5Pw = new PrintWriter(md5); final PrintWriter sha1Pw = new PrintWriter(sha1); final PrintWriter sha256Pw = new PrintWriter(sha256); for (final Map.Entry<String, Checksums> entry : checksums.entrySet()) { addChecksum(md5Pw, entry.getKey(), entry.getValue(), "MD5Sum"); addChecksum(sha1Pw, entry.getKey(), entry.getValue(), "SHA1"); addChecksum(sha256Pw, entry.getKey(), entry.getValue(), "SHA256"); } write(sw, "MD5Sum", md5.toString()); write(sw, "SHA1", sha1.toString()); write(sw, "SHA256", sha256.toString()); } final byte[] data = sw.toString().getBytes(StandardCharsets.UTF_8); handler.spoolOut(String.format("dists/%s/Release", dist.getName()), "text/plain", new ByteArrayInputStream(data)); if (this.signingService != null) { handler.spoolOut(String.format("dists/%s/Release.gpg", dist.getName()), "text/plain", new ByteArrayInputStream(sign(data, false))); handler.spoolOut(String.format("dists/%s/InRelease", dist.getName()), "text/plain", new ByteArrayInputStream(sign(data, true))); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); this.signingService.printPublicKey(bos); bos.close(); handler.spoolOut("GPG-KEY", "text/plain", new ByteArrayInputStream(bos.toByteArray())); } }
From source file:net.sourceforge.subsonic.controller.RESTController.java
public void getIndexes(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request);//from ww w . j a v a2 s .com XMLBuilder builder = createXMLBuilder(request, response, true); long ifModifiedSince = ServletRequestUtils.getLongParameter(request, "ifModifiedSince", 0L); long lastModified = leftController.getLastModified(request); if (lastModified <= ifModifiedSince) { builder.endAll(); response.getWriter().print(builder); return; } builder.add("indexes", "lastModified", lastModified, false); List<MusicFolder> musicFolders = settingsService.getAllMusicFolders(); Integer musicFolderId = ServletRequestUtils.getIntParameter(request, "musicFolderId"); if (musicFolderId != null) { for (MusicFolder musicFolder : musicFolders) { if (musicFolderId.equals(musicFolder.getId())) { musicFolders = Arrays.asList(musicFolder); break; } } } List<MediaFile> shortcuts = leftController.getShortcuts(musicFolders, settingsService.getShortcutsAsArray()); for (MediaFile shortcut : shortcuts) { builder.add("shortcut", true, new Attribute("name", shortcut.getName()), new Attribute("id", shortcut.getId())); } SortedMap<MusicIndex, SortedSet<MusicIndex.Artist>> indexedArtists = leftController .getMusicFolderContent(musicFolders).getIndexedArtists(); for (Map.Entry<MusicIndex, SortedSet<MusicIndex.Artist>> entry : indexedArtists.entrySet()) { builder.add("index", "name", entry.getKey().getIndex(), false); for (MusicIndex.Artist artist : entry.getValue()) { for (MediaFile mediaFile : artist.getMediaFiles()) { if (mediaFile.isDirectory()) { builder.add("artist", true, new Attribute("name", artist.getName()), new Attribute("id", mediaFile.getId())); } } } builder.end(); } // Add children Player player = playerService.getPlayer(request, response); List<MediaFile> singleSongs = leftController.getSingleSongs(musicFolders); for (MediaFile singleSong : singleSongs) { builder.add("child", createAttributesForMediaFile(player, singleSong), true); } builder.endAll(); response.getWriter().print(builder); }
From source file:org.apache.ctakes.ytex.kernel.SvmlinEvaluationParser.java
/** * support multi-class classification//from w w w . j a v a2 s . c om * * @param dataDir * @param outputDir * @param eval * @param fileBaseName * @param props * @param predict * @param listClassInfo * @throws IOException */ private void parseSvmlinOutput(File dataDir, File outputDir, SVMClassifierEvaluation eval, String fileBaseName, Properties props, List<InstanceClassInfo> listClassInfo, BiMap<Integer, String> classIdToNameMap) throws IOException { Properties codeProps = FileUtil .loadProperties(dataDir.getAbsolutePath() + "/" + fileBaseName + "code.properties", false); String[] codes = codeProps.getProperty("codes", "").split(","); SortedMap<String, double[]> codeToPredictionMap = new TreeMap<String, double[]>(); if (codes.length == 0) { throw new IOException("invalid code.properties: " + fileBaseName); } // int otherClassId = 0; String otherClassName = null; if (codes.length == 1) { // otherClassId = Integer // .parseInt(codeProps.getProperty("classOther")); otherClassName = codeProps.getProperty("classOtherName"); } for (String code : codes) { // determine class for given code // String strClassId = codeProps.getProperty(code+".class"); // if (strClassId == null) { // throw new IOException("invalid code.properties: " // + fileBaseName); // } // int classId = Integer.parseInt(strClassId); String className = codeProps.getProperty(code + ".className"); String codeBase = code.substring(0, code.length() - ".txt".length()); // read predictions for given class codeToPredictionMap.put(className, readPredictions( outputDir.getAbsolutePath() + "/" + codeBase + ".outputs", listClassInfo.size())); } // iterate over predictions for each instance, figure out which class is // the winner String[] classPredictions = new String[listClassInfo.size()]; for (int i = 0; i < listClassInfo.size(); i++) { if (otherClassName != null) { Map.Entry<String, double[]> classToPred = codeToPredictionMap.entrySet().iterator().next(); classPredictions[i] = classToPred.getValue()[i] > 0 ? classToPred.getKey() : otherClassName; } else { NavigableMap<Double, String> predToClassMap = new TreeMap<Double, String>(); for (Map.Entry<String, double[]> classToPred : codeToPredictionMap.entrySet()) { predToClassMap.put(classToPred.getValue()[i], classToPred.getKey()); } classPredictions[i] = predToClassMap.lastEntry().getValue(); } } boolean storeUnlabeled = YES.equalsIgnoreCase(props.getProperty(ParseOption.STORE_UNLABELED.getOptionKey(), ParseOption.STORE_UNLABELED.getDefaultValue())); updateSemiSupervisedPredictions(eval, listClassInfo, storeUnlabeled, classPredictions, classIdToNameMap.inverse()); }
From source file:org.jahia.tools.maven.plugins.LegalArtifactAggregator.java
public void resolveKnownLicensesByText(LicenseFile licenseFile) { List<KnownLicense> foundLicenses = new ArrayList<>(); String licenseText = licenseFile.getText(); if (knownLicenses.getLicenses() == null) { return;/* ww w . j a v a 2s . c om*/ } SortedMap<TextVariant, KnownLicense> textVariantsBySize = new TreeMap<>(new Comparator<TextVariant>() { @Override public int compare(TextVariant o1, TextVariant o2) { return o2.getText().length() - o1.getText().length(); } }); for (KnownLicense knownLicense : knownLicenses.getLicenses().values()) { for (TextVariant textVariant : knownLicense.getTextVariants()) { textVariantsBySize.put(textVariant, knownLicense); } } for (SortedMap.Entry<TextVariant, KnownLicense> textVariantBySizeEntry : textVariantsBySize.entrySet()) { Matcher textVariantMatcher = textVariantBySizeEntry.getKey().getCompiledTextPattern() .matcher(licenseText); if (textVariantMatcher.find()) { foundLicenses.add(textVariantBySizeEntry.getValue()); licenseText = licenseText.substring(textVariantMatcher.end()); break; } } if (foundLicenses.size() == 0) { System.out.println("No known license found for license file " + licenseFile.getFileName()); } licenseFile.setKnownLicenses(foundLicenses); if (StringUtils.isNotBlank(licenseText)) { licenseFile.setAdditionalLicenseText(licenseText); } }
From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetCalculationServiceImpl.java
/** * Calculate direct cost for given period *//*from ww w .j a va2 s . com*/ private ScaleTwoDecimal getCalculateBudgetSummaryExpenseTotal(BudgetPeriod budgetPeriod, boolean personnelFlag, String personnelCategoryTypeCode) { ScaleTwoDecimal calculatedExpenseTotal = ScaleTwoDecimal.ZERO; SortedMap<RateType, QueryList<BudgetLineItemCalculatedAmount>> uniqueLineItemCalAmounts = getBudgetSummaryUniqueRateTypeCalAmounts( budgetPeriod.getBudgetLineItems(), personnelFlag, personnelCategoryTypeCode); for (Map.Entry<RateType, QueryList<BudgetLineItemCalculatedAmount>> uniqueLineItem : uniqueLineItemCalAmounts .entrySet()) { RateType rateType = uniqueLineItem.getKey(); QueryList<BudgetLineItemCalculatedAmount> lineItemCalAmounts = uniqueLineItem.getValue(); RateClass rateClass = rateType.getRateClass(); if (isCalculatedDirectCostRate(personnelFlag, rateType, rateClass)) { ScaleTwoDecimal rateTypeTotalInThisPeriod = lineItemCalAmounts.sumObjects(CALCULATED_COST); calculatedExpenseTotal = calculatedExpenseTotal.add(rateTypeTotalInThisPeriod); } } return calculatedExpenseTotal; }
From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetCalculationServiceImpl.java
/** * This method is to group non-personnel items for budget summary * Start building data structure applicable for non-personnel items to format it with * required details for budget summary// w w w . j a va2 s . c o m */ private LineItemGroup getNonPersonnelBudgetSummaryPeriods(BudgetPeriod budgetPeriod, SortedMap<BudgetCategoryType, SortedMap<CostElement, List<BudgetLineItem>>> uniqueBudgetCategoryLineItemCostElements) { LineItemGroup nonPersonnelGroup = new LineItemGroup(BUDGET_SUMMARY_NONPERSONNEL_GROUP_LABEL, true); for (Map.Entry<BudgetCategoryType, SortedMap<CostElement, List<BudgetLineItem>>> uniqueBudgetCategory : uniqueBudgetCategoryLineItemCostElements .entrySet()) { ScaleTwoDecimal totalForCategory = ScaleTwoDecimal.ZERO; BudgetCategoryType budgetCategoryType = uniqueBudgetCategory.getKey(); SortedMap<CostElement, List<BudgetLineItem>> uniqueLineItemCostElements = uniqueBudgetCategory .getValue(); LineItemObject lineItemCategory = new LineItemObject(budgetCategoryType.getCode(), budgetCategoryType.getDescription(), ScaleTwoDecimal.ZERO); for (Map.Entry<CostElement, List<BudgetLineItem>> uniqueLineItem : uniqueLineItemCostElements .entrySet()) { CostElement costElement = uniqueLineItem.getKey(); QueryList<BudgetLineItem> periodLineItemCostElementQueryList = getLineItemsFilteredByCostElement( budgetPeriod, costElement.getCostElement()); ScaleTwoDecimal totalForCostElement = ScaleTwoDecimal.ZERO; if (periodLineItemCostElementQueryList != null) { totalForCostElement = periodLineItemCostElementQueryList.sumObjects("lineItemCost"); } LineItemObject costElementLineItemObject = new LineItemObject(costElement.getCostElement(), costElement.getDescription(), totalForCostElement); lineItemCategory.getLineItems().add(costElementLineItemObject); totalForCategory = totalForCategory.add(totalForCostElement); } lineItemCategory.setAmount(totalForCategory); nonPersonnelGroup.getLineItems().add(lineItemCategory); } return nonPersonnelGroup; }
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java
protected <T> ClosableIterator<RowResult<T>> postFilterIterator(final String tableName, RangeRequest range, int preFilterBatchSize, final Function<Value, T> transformer) { final BatchSizeIncreasingRangeIterator results = new BatchSizeIncreasingRangeIterator(tableName, range, preFilterBatchSize);//from w w w . j a v a 2 s .c om Iterator<Iterator<RowResult<T>>> batchedPostfiltered = new AbstractIterator<Iterator<RowResult<T>>>() { @Override protected Iterator<RowResult<T>> computeNext() { List<RowResult<Value>> batch = results.getBatch(); if (batch.isEmpty()) { return endOfData(); } SortedMap<Cell, T> postFilter = postFilterRows(tableName, batch, transformer); results.markNumRowsNotDeleted(Cells.getRows(postFilter.keySet()).size()); return Cells.createRowView(postFilter.entrySet()); } }; final Iterator<RowResult<T>> rows = Iterators.concat(batchedPostfiltered); return new ForwardingClosableIterator<RowResult<T>>() { @Override protected ClosableIterator<RowResult<T>> delegate() { return ClosableIterators.wrap(rows); } @Override public void close() { if (results != null) { results.close(); } } }; }
From source file:com.gdo.servlet.RpcWrapper.java
public void attributes(StclContext stclContext, RpcArgs args) { try {/*from w w w .j a v a2s .c o m*/ // gets stencils PStcl stcl = stclContext.getServletStcl(); // returns no attribute if no path if (StringUtils.isBlank(args.getPath())) { fault(stclContext, STENCILS_SERVICE, "empty path", args); return; } // returns attributes found // !! TODO Path attribute seems wrong SortedMap<IKey, String[]> map = stcl.getAttributes(stclContext, args.getPath(), args.getAttributePathes()); XmlStringWriter writer = new XmlStringWriter(args.getCharacterEncoding(stclContext)); writer.startElement("result"); addStatus(writer, Result.success()); writer.startElement("stencils"); writer.writeAttribute("size", map.size()); for (Entry<IKey, String[]> e : map.entrySet()) { writer.startElement("stencil"); writer.writeAttribute("key", e.getKey().toString()); writer.writeAttribute("attributes", e.getValue().length); int index = 0; for (String att : e.getValue()) { writer.writeAttribute("attr" + index, att); index++; } writer.endElement("stencil"); } writer.endElement("stencils"); writer.endElement("result"); // traces and responds String xml = writer.getString(); logTrace(stclContext, xml); StudioGdoServlet.writeXMLResponse(stclContext.getResponse(), xml, args.getCharacterEncoding(stclContext)); } catch (Exception e) { fault(stclContext, STENCILS_SERVICE, e, null); return; } }