List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:com.viridiansoftware.metrics.elasticsearch.ElasticsearchReporter.java
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { long timestamp = clock.getTime(); final DateTime dateTime = new DateTime(DateTimeZone.UTC); StringBuilder indexBuilder = new StringBuilder(); indexBuilder.append(elasticsearchIndexPrefix); indexBuilder.append(dateTime.getYear()); indexBuilder.append(DATE_DELIMETER); indexBuilder.append(TWO_DIGIT_FORMAT.format(dateTime.getMonthOfYear())); indexBuilder.append(DATE_DELIMETER); indexBuilder.append(TWO_DIGIT_FORMAT.format(dateTime.getDayOfMonth())); String index = indexBuilder.toString(); try {//from w w w . j ava2s . c o m for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { reportGauge(index, timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Counter> entry : counters.entrySet()) { reportCounter(index, timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { reportHistogram(index, timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Meter> entry : meters.entrySet()) { reportMetered(index, timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Timer> entry : timers.entrySet()) { reportTimer(index, timestamp, entry.getKey(), entry.getValue()); } sendBulkRequest(); } catch (IOException e) { LOGGER.warn("Unable to report to Elasticsearch", e); } }
From source file:org.jasig.schedassist.portlet.VisibleScheduleTag.java
/** * Render a single week.// w w w . j av a2s . com * * @param writer * @param weekNumber * @param dailySchedules * @param scheduleBlockMap * @param renderRequest * @param renderResponse * @throws IOException */ protected void renderWeek(final JspWriter writer, final int weekNumber, final SortedMap<Date, List<AvailableBlock>> dailySchedules, final SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap, final RenderRequest renderRequest, final RenderResponse renderResponse) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("begin renderWeek for " + weekNumber); } final boolean hasBlocks = doesWeekHaveBlocks(dailySchedules); if (hasBlocks) { final SimpleDateFormat headFormat = new SimpleDateFormat("EEE M/d"); writer.write("<div class=\"weekcontainer\" id=\"week" + weekNumber + "\">"); for (Map.Entry<Date, List<AvailableBlock>> entry : dailySchedules.entrySet()) { final Date day = entry.getKey(); final List<AvailableBlock> daySchedule = entry.getValue(); if (LOG.isDebugEnabled()) { LOG.debug("in renderWeek weeknumber: " + weekNumber + ", day: " + day); } if (daySchedule.size() > 0) { writer.write("<div class=\"weekday\">"); writer.write("<ul>"); writer.write("<li class=\"dayhead\">"); writer.write(headFormat.format(day)); writer.write("</li>"); for (AvailableBlock event : daySchedule) { AvailableStatus eventStatus = scheduleBlockMap.get(event); if (AvailableStatus.BUSY.equals(eventStatus)) { renderBusyBlock(writer, event); } else if (AvailableStatus.FREE.equals(eventStatus)) { renderFreeBlock(writer, event, renderRequest, renderResponse); } else if (AvailableStatus.ATTENDING.equals(eventStatus)) { renderAttendingBlock(writer, event, renderRequest, renderResponse); } } writer.write("</ul>"); writer.write("</div> <!-- end weekday -->"); } } writer.write("</div> <!-- end weekcontainer -->"); } else { if (LOG.isDebugEnabled()) { LOG.debug("renderWeek has no blocks for weekNumber: " + weekNumber); } } }
From source file:org.apache.ctakes.ytex.kernel.FoldGeneratorImpl.java
@Override public SortedMap<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>> generateRuns( SortedMap<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>> labelToInstanceMap, int nFolds, int nMinPerClass, Integer nSeed, int nRuns) { // allocate map to return SortedMap<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>> labelToInstanceFoldMap = new TreeMap<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>>(); // initialize random seed Random r = new Random(nSeed != null ? nSeed : System.currentTimeMillis()); // iterate over labels for (Map.Entry<String, SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>> labelRun : labelToInstanceMap .entrySet()) {/*w w w. ja v a 2 s. c o m*/ String label = labelRun.getKey(); // extract the instance id - class map SortedMap<Long, String> instanceClassMap = labelRun.getValue().get(0).get(0).get(true); // allocate the run to fold map SortedMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>> runMap = new TreeMap<Integer, SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>>(); labelToInstanceFoldMap.put(label, runMap); // iterate over runs for (int run = 1; run <= nRuns; run++) { // generate folds for run List<Set<Long>> folds = createFolds(nFolds, nMinPerClass, r, instanceClassMap); SortedMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>> foldMap = new TreeMap<Integer, SortedMap<Boolean, SortedMap<Long, String>>>(); // add the fold map to the run map runMap.put(run, foldMap); // iterate over folds for (int trainFoldNum = 1; trainFoldNum <= folds.size(); trainFoldNum++) { // add train/test sets for the fold SortedMap<Boolean, SortedMap<Long, String>> trainTestMap = new TreeMap<Boolean, SortedMap<Long, String>>(); foldMap.put(trainFoldNum, trainTestMap); trainTestMap.put(true, new TreeMap<Long, String>()); trainTestMap.put(false, new TreeMap<Long, String>()); // populate the train/test sets Set<Long> testIds = folds.get(trainFoldNum - 1); // iterate over all instances for (Map.Entry<Long, String> instanceClass : instanceClassMap.entrySet()) { long instanceId = instanceClass.getKey(); String clazz = instanceClass.getValue(); // add the instance to the test set if it is in testIds, // else to the train set trainTestMap.get(!testIds.contains(instanceId)).put(instanceId, clazz); } } } } return labelToInstanceFoldMap; }
From source file:org.codehaus.mojo.license.LicenseMap.java
public SortedMap<MavenProject, String[]> toDependencyMap() { SortedMap<MavenProject, Set<String>> tmp = new TreeMap<MavenProject, Set<String>>( ArtifactHelper.getProjectComparator()); for (Map.Entry<String, SortedSet<MavenProject>> entry : entrySet()) { String license = entry.getKey(); SortedSet<MavenProject> set = entry.getValue(); for (MavenProject p : set) { Set<String> list = tmp.get(p); if (list == null) { list = new HashSet<String>(); tmp.put(p, list);//from w w w.j a va 2 s. c o m } list.add(license); } } SortedMap<MavenProject, String[]> result = new TreeMap<MavenProject, String[]>( ArtifactHelper.getProjectComparator()); for (Map.Entry<MavenProject, Set<String>> entry : tmp.entrySet()) { List<String> value = new ArrayList<String>(entry.getValue()); Collections.sort(value); result.put(entry.getKey(), value.toArray(new String[value.size()])); } tmp.clear(); return result; }
From source file:org.apache.hadoop.hbase.MetaTableAccessor.java
/** * Returns an HRegionLocationList extracted from the result. * @return an HRegionLocationList containing all locations for the region range or null if * we can't deserialize the result.// w w w. j a v a 2 s.c o m */ @Nullable public static RegionLocations getRegionLocations(final Result r) { if (r == null) return null; HRegionInfo regionInfo = getHRegionInfo(r, getRegionInfoColumn()); if (regionInfo == null) return null; List<HRegionLocation> locations = new ArrayList<HRegionLocation>(1); NavigableMap<byte[], NavigableMap<byte[], byte[]>> familyMap = r.getNoVersionMap(); locations.add(getRegionLocation(r, regionInfo, 0)); NavigableMap<byte[], byte[]> infoMap = familyMap.get(getCatalogFamily()); if (infoMap == null) return new RegionLocations(locations); // iterate until all serverName columns are seen int replicaId = 0; byte[] serverColumn = getServerColumn(replicaId); SortedMap<byte[], byte[]> serverMap = infoMap.tailMap(serverColumn, false); if (serverMap.isEmpty()) return new RegionLocations(locations); for (Map.Entry<byte[], byte[]> entry : serverMap.entrySet()) { replicaId = parseReplicaIdFromServerColumn(entry.getKey()); if (replicaId < 0) { break; } HRegionLocation location = getRegionLocation(r, regionInfo, replicaId); // In case the region replica is newly created, it's location might be null. We usually do not // have HRL's in RegionLocations object with null ServerName. They are handled as null HRLs. if (location == null || location.getServerName() == null) { locations.add(null); } else { locations.add(location); } } return new RegionLocations(locations); }
From source file:org.apache.sling.commons.metrics.internal.MetricWebConsolePlugin.java
private void addGaugeDetails(PrintWriter pw, SortedMap<String, Gauge> gauges) { if (gauges.isEmpty()) { return;/*w w w.ja v a2s . c o m*/ } pw.println("<br>"); pw.println("<div class='table'>"); pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Gauges</div>"); pw.println("<table class='nicetable' id='data-guages'>"); pw.println("<thead>"); pw.println("<tr>"); pw.println("<th class='header'>Name</th>"); pw.println("<th class='header'>Value</th>"); pw.println("</tr>"); pw.println("</thead>"); pw.println("<tbody>"); String rowClass = "odd"; for (Map.Entry<String, Gauge> e : gauges.entrySet()) { Gauge g = e.getValue(); String name = e.getKey(); pw.printf("<tr class='%s ui-state-default'>%n", rowClass); pw.printf("<td>%s</td>", name); pw.printf("<td>%s</td>", g.getValue()); pw.println("</tr>"); rowClass = "odd".equals(rowClass) ? "even" : "odd"; } pw.println("</tbody>"); pw.println("</table>"); pw.println("</div>"); }
From source file:org.apache.lens.server.session.HiveSessionService.java
/** * {@inheritDoc}/*from w w w. j ava 2 s. c o m*/ */ @Override public List<String> getAllSessionParameters(LensSessionHandle sessionid, boolean verbose, String key) throws LensException { List<String> result = new ArrayList<String>(); acquire(sessionid); try { SessionState ss = getSession(sessionid).getSessionState(); if (!StringUtils.isBlank(key)) { result.add(getSessionParam(getSession(sessionid).getSessionConf(), ss, key)); } else { SortedMap<String, String> sortedMap = new TreeMap<String, String>(); sortedMap.put("silent", (ss.getIsSilent() ? "on" : "off")); for (String s : ss.getHiveVariables().keySet()) { sortedMap.put(SystemVariables.HIVEVAR_PREFIX + s, ss.getHiveVariables().get(s)); } for (Map.Entry<String, String> entry : getSession(sessionid).getSessionConf()) { sortedMap.put(entry.getKey(), entry.getValue()); } for (Map.Entry<String, String> entry : sortedMap.entrySet()) { result.add(entry.toString()); } } } finally { release(sessionid); } return result; }
From source file:io.anserini.search.SearchWebCollection.java
/** * Prints TREC submission file to the standard output stream. * * @param topics queries// w ww . ja va 2 s .c o m * @param similarity similarity * @throws IOException * @throws ParseException */ public void search(SortedMap<Integer, String> topics, String submissionFile, Similarity similarity, int numHits, RerankerCascade cascade, boolean useQueryParser, boolean keepstopwords) throws IOException, ParseException { IndexSearcher searcher = new IndexSearcher(reader); searcher.setSimilarity(similarity); final String runTag = "BM25_EnglishAnalyzer_" + (keepstopwords ? "KeepStopwords_" : "") + FIELD_BODY + "_" + similarity.toString(); PrintWriter out = new PrintWriter( Files.newBufferedWriter(Paths.get(submissionFile), StandardCharsets.US_ASCII)); EnglishAnalyzer ea = keepstopwords ? new EnglishAnalyzer(CharArraySet.EMPTY_SET) : new EnglishAnalyzer(); QueryParser queryParser = new QueryParser(FIELD_BODY, ea); queryParser.setDefaultOperator(QueryParser.Operator.OR); for (Map.Entry<Integer, String> entry : topics.entrySet()) { int qID = entry.getKey(); String queryString = entry.getValue(); Query query = useQueryParser ? queryParser.parse(queryString) : AnalyzerUtils.buildBagOfWordsQuery(FIELD_BODY, ea, queryString); /** * For Web Tracks 2010,2011,and 2012; an experimental run consists of the top 10,000 documents for each topic query. */ TopDocs rs = searcher.search(query, numHits); ScoreDoc[] hits = rs.scoreDocs; List<String> queryTokens = AnalyzerUtils.tokenize(ea, queryString); RerankerContext context = new RerankerContext(searcher, query, String.valueOf(qID), queryString, queryTokens, FIELD_BODY, null); ScoredDocuments docs = cascade.run(ScoredDocuments.fromTopDocs(rs, searcher), context); /** * the first column is the topic number. * the second column is currently unused and should always be "Q0". * the third column is the official document identifier of the retrieved document. * the fourth column is the rank the document is retrieved. * the fifth column shows the score (integer or floating point) that generated the ranking. * the sixth column is called the "run tag" and should be a unique identifier for your */ for (int i = 0; i < docs.documents.length; i++) { out.println(String.format("%d Q0 %s %d %f %s", qID, docs.documents[i].getField(FIELD_ID).stringValue(), (i + 1), docs.scores[i], runTag)); } } out.flush(); out.close(); }
From source file:org.alfresco.repo.domain.node.NodePropertyHelper.java
public Map<QName, Serializable> convertToPublicProperties( Map<NodePropertyKey, NodePropertyValue> propertyValues) { Map<QName, Serializable> propertyMap = new HashMap<QName, Serializable>(propertyValues.size(), 1.0F); // Shortcut// w ww . j a va 2 s.com if (propertyValues.size() == 0) { return propertyMap; } // We need to process the properties in order SortedMap<NodePropertyKey, NodePropertyValue> sortedPropertyValues = new TreeMap<NodePropertyKey, NodePropertyValue>( propertyValues); // A working map. Ordering is important. SortedMap<NodePropertyKey, NodePropertyValue> scratch = new TreeMap<NodePropertyKey, NodePropertyValue>(); // Iterate (sorted) over the map entries and extract values with the same qname Long currentQNameId = Long.MIN_VALUE; Iterator<Map.Entry<NodePropertyKey, NodePropertyValue>> iterator = sortedPropertyValues.entrySet() .iterator(); while (true) { Long nextQNameId = null; NodePropertyKey nextPropertyKey = null; NodePropertyValue nextPropertyValue = null; // Record the next entry's values if (iterator.hasNext()) { Map.Entry<NodePropertyKey, NodePropertyValue> entry = iterator.next(); nextPropertyKey = entry.getKey(); nextPropertyValue = entry.getValue(); nextQNameId = nextPropertyKey.getQnameId(); } // If the QName is going to change, and we have some entries to process, then process them. if (scratch.size() > 0 && (nextQNameId == null || !nextQNameId.equals(currentQNameId))) { QName currentQName = qnameDAO.getQName(currentQNameId).getSecond(); PropertyDefinition currentPropertyDef = dictionaryService.getProperty(currentQName); // We have added something to the scratch properties but the qname has just changed Serializable collapsedValue = null; // We can shortcut if there is only one value if (scratch.size() == 1) { // There is no need to collapse list indexes collapsedValue = collapsePropertiesWithSameQNameAndListIndex(currentPropertyDef, scratch); } else { // There is more than one value so the list indexes need to be collapsed collapsedValue = collapsePropertiesWithSameQName(currentPropertyDef, scratch); } boolean forceCollection = false; // If the property is multi-valued then the output property must be a collection if (currentPropertyDef != null && currentPropertyDef.isMultiValued()) { forceCollection = true; } else if (scratch.size() == 1 && scratch.firstKey().getListIndex().intValue() > -1) { // This is to handle cases of collections where the property is d:any but not // declared as multiple. forceCollection = true; } if (forceCollection && collapsedValue != null && !(collapsedValue instanceof Collection<?>)) { // Can't use Collections.singletonList: ETHREEOH-1172 ArrayList<Serializable> collection = new ArrayList<Serializable>(1); collection.add(collapsedValue); collapsedValue = collection; } // Store the value propertyMap.put(currentQName, collapsedValue); // Reset scratch.clear(); } if (nextQNameId != null) { // Add to the current entries scratch.put(nextPropertyKey, nextPropertyValue); currentQNameId = nextQNameId; } else { // There is no next value to process break; } } // Done return propertyMap; }
From source file:org.apache.sling.commons.metrics.internal.MetricWebConsolePlugin.java
private void addCounterDetails(PrintWriter pw, SortedMap<String, Counter> counters) { if (counters.isEmpty()) { return;/*from www. ja va 2 s. c o m*/ } pw.println("<br>"); pw.println("<div class='table'>"); pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Counters</div>"); pw.println("<table class='nicetable' id='data-counters'>"); pw.println("<thead>"); pw.println("<tr>"); pw.println("<th class='header'>Name</th>"); pw.println("<th class='header'>Count</th>"); pw.println("</tr>"); pw.println("</thead>"); pw.println("<tbody>"); String rowClass = "odd"; for (Map.Entry<String, Counter> e : counters.entrySet()) { Counter c = e.getValue(); String name = e.getKey(); pw.printf("<tr class='%s ui-state-default'>%n", rowClass); pw.printf("<td>%s</td>", name); pw.printf("<td>%d</td>", c.getCount()); pw.println("</tr>"); rowClass = "odd".equals(rowClass) ? "even" : "odd"; } pw.println("</tbody>"); pw.println("</table>"); pw.println("</div>"); }