List of usage examples for java.util TreeMap entrySet
EntrySet entrySet
To view the source code for java.util TreeMap entrySet.
Click Source Link
From source file:org.opencms.workplace.explorer.CmsNewResourceXmlPage.java
/** * Builds the html for the page body file select box.<p> * //from ww w .j av a2 s .c o m * @param attributes optional attributes for the <select> tag * * @return the html for the page body file select box */ public String buildSelectBodyFile(String attributes) { List options = new ArrayList(); List values = new ArrayList(); TreeMap bodies = null; try { // get all available body files bodies = getBodies(getCms(), getParamCurrentFolder(), false); } catch (CmsException e) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(e); } } if (bodies == null) { // no body files found, return empty String return ""; } else { // body files found, create option and value lists Iterator i = bodies.entrySet().iterator(); int counter = 0; while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String key = (String) entry.getKey(); String path = (String) entry.getValue(); options.add(key); values.add(path); counter++; } } return buildSelect(attributes, options, values, -1, false); }
From source file:com.turn.splicer.Config.java
public void writeAsJson(JsonGenerator jgen) throws IOException { if (properties == null) { jgen.writeStartObject();/* w w w . ja v a 2 s . c o m*/ jgen.writeEndObject(); return; } TreeMap<String, String> map = new TreeMap<>(); for (Map.Entry<Object, Object> e : properties.entrySet()) { map.put(String.valueOf(e.getKey()), String.valueOf(e.getValue())); } InputStream is = getClass().getClassLoader().getResourceAsStream(VERSION_FILE); if (is != null) { LOG.debug("Loaded {} bytes of version file configuration", is.available()); Properties versionProps = new Properties(); versionProps.load(is); for (Map.Entry<Object, Object> e : versionProps.entrySet()) { map.put(String.valueOf(e.getKey()), String.valueOf(e.getValue())); } } else { LOG.error("No version file found on classpath. VERSION_FILE={}", VERSION_FILE); } jgen.writeStartObject(); for (Map.Entry<String, String> e : map.entrySet()) { if (e.getValue().indexOf(',') > 0) { splitList(e.getKey(), e.getValue(), jgen); } else { jgen.writeStringField(e.getKey(), e.getValue()); } } jgen.writeEndObject(); }
From source file:org.alfresco.bm.report.XLSXReporter.java
/** * Create a 'Summary' sheet containing the table of averages *///from w w w. j av a2 s .co m private void createSummarySheet(XSSFWorkbook workbook) throws IOException, NotFoundException { DBObject testRunObj = getTestService().getTestRunMetadata(test, run); // Create the sheet XSSFSheet sheet = workbook.createSheet("Summary"); // Create the fonts we need Font fontBold = workbook.createFont(); fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD); // Create the styles we need XSSFCellStyle summaryDataStyle = sheet.getWorkbook().createCellStyle(); summaryDataStyle.setAlignment(HorizontalAlignment.RIGHT); XSSFCellStyle headerStyle = sheet.getWorkbook().createCellStyle(); headerStyle.setAlignment(HorizontalAlignment.RIGHT); headerStyle.setFont(fontBold); XSSFRow row = null; int rowCount = 0; row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Name:"); row.getCell(0).setCellStyle(headerStyle); row.getCell(1).setCellValue(title); row.getCell(1).setCellStyle(summaryDataStyle); } row = sheet.createRow(rowCount++); { String description = (String) testRunObj.get(FIELD_DESCRIPTION); description = description == null ? "" : description; row.getCell(0).setCellValue("Description:"); row.getCell(0).setCellStyle(headerStyle); row.getCell(1).setCellValue(description); row.getCell(1).setCellStyle(summaryDataStyle); } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Progress (%):"); row.getCell(0).setCellStyle(headerStyle); Double progress = (Double) testRunObj.get(FIELD_PROGRESS); progress = progress == null ? 0.0 : progress; row.getCell(1).setCellValue(progress * 100); row.getCell(1).setCellType(XSSFCell.CELL_TYPE_NUMERIC); row.getCell(1).setCellStyle(summaryDataStyle); } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("State:"); row.getCell(0).setCellStyle(headerStyle); String state = (String) testRunObj.get(FIELD_STATE); if (state != null) { row.getCell(1).setCellValue(state); row.getCell(1).setCellStyle(summaryDataStyle); } } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Started:"); row.getCell(0).setCellStyle(headerStyle); Long time = (Long) testRunObj.get(FIELD_STARTED); if (time > 0) { row.getCell(1).setCellValue(FastDateFormat .getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM).format(time)); row.getCell(1).setCellStyle(summaryDataStyle); } } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Finished:"); row.getCell(0).setCellStyle(headerStyle); Long time = (Long) testRunObj.get(FIELD_COMPLETED); if (time > 0) { row.getCell(1).setCellValue(FastDateFormat .getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM).format(time)); row.getCell(1).setCellStyle(summaryDataStyle); } } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Duration:"); row.getCell(0).setCellStyle(headerStyle); Long time = (Long) testRunObj.get(FIELD_DURATION); if (time > 0) { row.getCell(1).setCellValue(DurationFormatUtils.formatDurationHMS(time)); row.getCell(1).setCellStyle(summaryDataStyle); } } rowCount++; rowCount++; // Create a header row row = sheet.createRow(rowCount++); // Header row String[] headers = new String[] { "Event Name", "Total Count", "Success Count", "Failure Count", "Success Rate (%)", "Min (ms)", "Max (ms)", "Arithmetic Mean (ms)", "Standard Deviation (ms)" }; int columnCount = 0; for (String header : headers) { XSSFCell cell = row.getCell(columnCount++); cell.setCellStyle(headerStyle); cell.setCellValue(header); } // Grab results and output them columnCount = 0; TreeMap<String, ResultSummary> summaries = collateResults(true); for (Map.Entry<String, ResultSummary> entry : summaries.entrySet()) { // Reset column count columnCount = 0; row = sheet.createRow(rowCount++); String eventName = entry.getKey(); ResultSummary summary = entry.getValue(); SummaryStatistics statsSuccess = summary.getStats(true); SummaryStatistics statsFail = summary.getStats(false); // Event Name row.getCell(columnCount++).setCellValue(eventName); // Total Count row.getCell(columnCount++).setCellValue(summary.getTotalResults()); // Success Count row.getCell(columnCount++).setCellValue(statsSuccess.getN()); // Failure Count row.getCell(columnCount++).setCellValue(statsFail.getN()); // Success Rate (%) row.getCell(columnCount++).setCellValue(summary.getSuccessPercentage()); // Min (ms) row.getCell(columnCount++).setCellValue((long) statsSuccess.getMin()); // Max (ms) row.getCell(columnCount++).setCellValue((long) statsSuccess.getMax()); // Arithmetic Mean (ms) row.getCell(columnCount++).setCellValue((long) statsSuccess.getMean()); // Standard Deviation (ms) row.getCell(columnCount++).setCellValue((long) statsSuccess.getStandardDeviation()); } // Auto-size the columns for (int i = 0; i < 10; i++) { sheet.autoSizeColumn(i); } sheet.setColumnWidth(1, 5120); // Printing PrintSetup ps = sheet.getPrintSetup(); sheet.setAutobreaks(true); ps.setFitWidth((short) 1); ps.setLandscape(true); // Header and footer sheet.getHeader().setCenter(title); }
From source file:org.opencms.workplace.explorer.CmsNewResourceXmlPage.java
/** * Builds the html for the page template select box.<p> * //from w w w . j av a 2 s . co m * @param attributes optional attributes for the <select> tag * * @return the html for the page template select box */ public String buildSelectTemplates(String attributes) { List options = new ArrayList(); List values = new ArrayList(); TreeMap templates = null; try { // get all available templates templates = getTemplates(getCms(), getParamCurrentFolder(), false); } catch (CmsException e) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(e); } } if (templates == null) { // no templates found, return empty String return ""; } else { // templates found, create option and value lists Iterator i = templates.entrySet().iterator(); int counter = 0; while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String key = (String) entry.getKey(); String path = (String) entry.getValue(); options.add(key); values.add(path); counter++; } } return buildSelect(attributes, options, values, -1, false); }
From source file:com.ibm.bi.dml.debug.DMLDebuggerFunctions.java
/** * Print all breakpoints along with current status (i.e. enabled or disabled) * @param breakpoints Contains all existing breakpoints *///from ww w . jav a 2 s. co m public void listBreakpoints(TreeMap<Integer, BreakPointInstruction> breakpoints) { //Display all breakpoints if (breakpoints == null) { System.out.println("No breakpoints are set for this program."); return; } int currBreakpoint = 1; //active breakpoint ids int numVisibleBreakpoints = 0; for (Entry<Integer, BreakPointInstruction> e : breakpoints.entrySet()) { Integer lineNumber = e.getKey(); BreakPointInstruction inst = e.getValue(); if (inst.getBPInstructionStatus() == BPINSTRUCTION_STATUS.ENABLED) { System.out.format("Breakpoint %2d, at line %4d (%s)\n", currBreakpoint++, lineNumber, "enabled"); numVisibleBreakpoints++; } else if (inst.getBPInstructionStatus() == BPINSTRUCTION_STATUS.DISABLED) { System.out.format("Breakpoint %2d, at line %4d (%s)\n", currBreakpoint++, lineNumber, "disabled"); numVisibleBreakpoints++; } } if (numVisibleBreakpoints == 0) { System.out.println("No breakpoints are set for this program."); } }
From source file:org.lockss.servlet.AddContentTab.java
private void createAuRow(Table divTable, TreeMap<String, List<TitleConfig>> titleConfigs, String cleanNameString) throws UnsupportedEncodingException { for (Map.Entry<String, List<TitleConfig>> pairs : titleConfigs.entrySet()) { String title = pairs.getKey(); String cleanTitleString = cleanName(title); List<TitleConfig> configList = pairs.getValue(); divTable.newRow();//www . j av a 2s . co m Block columnDiv = divTable.row(); columnDiv.attribute("id", cleanName(title) + "_column"); columnDiv.attribute("class", "journal-title " + cleanNameString + "_class hide-row"); for (String columnArray : columnArrayList) { Block columnHeader = new Block(Block.Bold); columnHeader.add(columnArray); divTable.addCell(columnHeader, "class=\"column-header\""); } divTable.newRow(); Block titleDiv = divTable.row(); titleDiv.attribute("id", cleanName(title) + "_title"); titleDiv.attribute("class", "journal-title " + cleanNameString + "_class hide-row"); Table titleTable = new Table(); titleTable.attribute("class", "title-table"); Input titleCheckbox = new Input(Input.Checkbox, cleanNameString + "_checkbox"); titleCheckbox.attribute("onClick", "titleCheckbox(this, \"" + cleanTitleString + "\")"); titleCheckbox.attribute("class", "chkbox"); Block titleCheckboxDiv = new Block(Block.Div); titleCheckboxDiv.attribute("class", "checkboxDiv"); titleCheckboxDiv.add(titleCheckbox); divTable.addCell(titleCheckboxDiv, "class=\"checkboxDiv\""); addTitleRow(titleTable, "Title:", HtmlUtil.encode(title, HtmlUtil.ENCODE_TEXT)); addTitleRow(titleTable, "Print ISSN:", configList.get(0).getTdbAu().getIssn()); addTitleRow(titleTable, "E-ISSN:", configList.get(0).getTdbAu().getEissn()); divTable.addCell(titleTable, "colspan=\"7\""); int rowCount = 0; for (TitleConfig tc : configList) { String rowClass = rowCss(rowCount); TdbAu tdbAu = tc.getTdbAu(); ArchivalUnit au = pluginMgr.getAuFromId(tc.getAuId(pluginMgr)); String auName = HtmlUtil.encode(tc.getDisplayName(), HtmlUtil.ENCODE_TEXT); String cleanedAuName = cleanAuName(auName); divTable.newRow(); Block newRow = divTable.row(); newRow.attribute("class", cleanNameString + "_class hide-row " + rowClass); if (au == null) { if (tdbAu != null) { createInactiveRow(divTable, auName, cleanTitleString, tc); } else { createEmptyRow(divTable, auName, cleanNameString, rowCount, tc); } } else { createActiveRow(divTable, auName, cleanNameString, cleanTitleString, au); } divTable.newRow("class='hide-row " + rowClass + " " + cleanNameString + "-au' id='" + cleanedAuName + "_row'"); Block detailsDiv = new Block(Block.Div); detailsDiv.attribute("id", cleanedAuName + "_cell"); detailsDiv.attribute("class", rowClass); divTable.addCell(detailsDiv, "colspan='8' id='" + cleanedAuName + "'"); } addClearRow(divTable, cleanNameString, true); } }
From source file:org.commoncrawl.service.listcrawler.CrawlHistoryManager.java
private static void testWriteMapFileToHDFS(EventLoop eventLoop) { try {/*w w w . jav a2s . c o m*/ // initialize log manager CrawlHistoryManager logManager = initializeTestLogManager(eventLoop, true); // initialize item list TreeMap<URLFP, ProxyCrawlHistoryItem> items = buildTestList(urlList1); final TreeMap<String, URLFP> urlToURLFPMap = new TreeMap<String, URLFP>(); for (Map.Entry<URLFP, ProxyCrawlHistoryItem> item : items.entrySet()) { urlToURLFPMap.put(item.getValue().getOriginalURL(), item.getKey()); } // add to local item map in log manager for (ProxyCrawlHistoryItem item : items.values()) { logManager.appendItemToLog(item); } // ok shutdown log manager ... logManager.shutdown(); // restart - reload log file ... logManager = initializeTestLogManager(eventLoop, false); // write to 'hdfs' logManager.doCheckpoint(); syncAndValidateItems(items, logManager); logManager.shutdown(); // restart logManager = initializeTestLogManager(eventLoop, false); // tweak original items updateTestItemStates(items); // ok append items for (ProxyCrawlHistoryItem item : items.values()) { logManager.appendItemToLog(item); } syncAndValidateItems(items, logManager); // ok now checkpoint the items logManager.doCheckpoint(); // ok now validate one last time syncAndValidateItems(items, logManager); // shutown logManager.shutdown(); logManager = null; { // start from scratch ... final CrawlHistoryManager logManagerTest = initializeTestLogManager(eventLoop, true); // create a final version of the tree map reference final TreeMap<URLFP, ProxyCrawlHistoryItem> itemList = items; // create filename File urlInputFile = new File(logManagerTest.getLocalDataDir(), "testURLS-" + System.currentTimeMillis()); // ok create a crawl list from urls CrawlList.generateTestURLFile(urlInputFile, urlList1); long listId = logManagerTest.loadList(urlInputFile, 0); CrawlList listObject = logManagerTest.getList(listId); final Semaphore listCompletionSemaphore = new Semaphore(-(itemList.size() - 1)); listObject.setEventListener(new CrawlList.CrawlListEvents() { @Override public void itemUpdated(URLFP itemFingerprint) { // TODO Auto-generated method stub listCompletionSemaphore.release(); } }); // ok start the appropriate threads logManagerTest.startLogWriterThread(0); logManagerTest.startListLoaderThread(); logManagerTest.startQueueLoaderThread(new CrawlQueueLoader() { @Override public void queueURL(URLFP urlfp, String url) { logManagerTest.crawlComplete( proxyCrawlHitoryItemToCrawlURL(itemList.get(urlToURLFPMap.get(url)))); } @Override public void flush() { // TODO Auto-generated method stub } }); LOG.info("Waiting for Release"); // and wait for the finish listCompletionSemaphore.acquireUninterruptibly(); LOG.info("Got Here"); } } catch (IOException e) { LOG.error(CCStringUtils.stringifyException(e)); } }
From source file:com.samples.platform.core.security.UserProvider.java
/** * Read the user definitions out of the properties and put the into the map * {@link UserProvider#userMap}./*from w w w .j a va 2s . co m*/ */ public void createUsers() { this.logger.trace("+createUsers"); /* Create an _sorted_ map containing all user definition properties. */ TreeMap<String, String> userDefinitionProperties = new TreeMap<String, String>(); for (Map.Entry<String, String> entry : this.properties.getProperties().entrySet()) { if (entry.getKey() != null && entry.getKey().startsWith(BUS_PROPERTY_NAME_START)) { userDefinitionProperties.put(entry.getKey(), entry.getValue()); } } /* Create a map of UserDefinitions parsed out of the properties. */ HashMap<String, UserDefinition> parsedUserDefinitions = new HashMap<String, UserProvider.UserDefinition>(); UserDefinition userDefinition = null; String userKey = null; for (Map.Entry<String, String> userDefinitionProperty : userDefinitionProperties.entrySet()) { /* Get the user key out of the property name. */ userKey = extractUser(userDefinitionProperty.getKey()); if (userDefinition == null || !userDefinition.getKey().equals(userKey)) { /* New user key extracted out of the property name. */ if (userDefinition != null) { /* Previous UserDefinition finished. Put it into the map. */ parsedUserDefinitions.put(userDefinition.getName(), userDefinition); } /* Create the actual UserDefinition with the user key. */ userDefinition = new UserDefinition(userKey); } /* Setup the content of the property into the UserDefinition. */ if (userDefinitionProperty.getKey().endsWith("userName")) { userDefinition.setName(userDefinitionProperty.getValue()); } else if (userDefinitionProperty.getKey().endsWith("password")) { userDefinition.setPassword(userDefinitionProperty.getValue()); } else if (userDefinitionProperty.getKey().contains(".role.")) { if (userDefinitionProperty.getValue() != null && !userDefinitionProperty.getValue().equals(ROLE_ANONYMOUS)) { userDefinition.addRolename(userDefinitionProperty.getValue()); } } } /* Put the last UserDefinition to the map of parsedUserDefinitions. */ if (userDefinition != null && userDefinition.getName() != null) { parsedUserDefinitions.put(userDefinition.getName(), userDefinition); } /* * Update the userMap. If the userName of the userMap is not part of the * parsedUserDefinitions any more, the user is removed out of the * userMap. */ List<String> keyList = new ArrayList<String>(this.userMap.size()); Collections.addAll(keyList, this.userMap.keySet().toArray(new String[this.userMap.keySet().size()])); for (String userName : keyList) { userDefinition = parsedUserDefinitions.get(userName); if (!parsedUserDefinitions.containsKey(userName)) { this.userMap.remove(userName); } } /* * All UserDefinitions out of the parsedUserDefinitions are mapped to a * User and put into the userMap. */ for (UserDefinition ud : parsedUserDefinitions.values()) { this.userMap.put(ud.getName(), this.getUser(ud)); } this.logger.trace("-createUsers"); }
From source file:edu.jhu.cvrg.servlet.TSDBBacking.java
public String retrieveSingleLead(String subjectId, String metric, long unixTimeStart, long unixTimeEnd, String downsampleRate) throws OpenTSDBException { //pause();//from www. j a va2 s .c o m HashMap<String, String> tags = new HashMap<String, String>(); if (metric.startsWith("ecg")) { tags.put("subjectId", subjectId); } JSONObject dataForView; String finalDataString = ""; //Interval Annotation result is {"tsuid":"00005900000200036A00000400036B","description":"Test Annotation 20160405 - //text for additional interval notation","notes":"","endTime":1420070467,"startTime":1420070465} try { dataForView = TimeSeriesRetriever.getDownsampledTimeSeries(OPENTSDB_URL, unixTimeStart, unixTimeEnd, metric, downsampleRate, tags, OPENTSDB_BOO); double sampRate = 1; double aduGain = 1; JSONObject rawData = new JSONObject(); String leadMetric = ""; JSONObject leadTags = new JSONObject(); //System.out.println(dataForView); rawData = dataForView.getJSONObject("dps"); leadMetric = dataForView.getString("metric"); leadTags = dataForView.getJSONObject("tags"); DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); // if (leadMetric != null){ // //System.out.println(leadMetric + ": lead Metric"); // } if (!leadTags.isNull("format")) { String value = leadTags.getString("format"); switch (value.toLowerCase()) { case "phillips103": sampRate = 2; // 1000 / 500 (original sample rate) aduGain = 2; break; case "phillips104": sampRate = 2; aduGain = 2; break; case "schiller": sampRate = 2; aduGain = 2; break; case "hl7aecg": sampRate = 1; // 1000 / 1000 (original sample rate) aduGain = 0.025; break; case "gemusexml": sampRate = 4; // 1000 / 250 (original sample rate) aduGain = 2.05; break; default: break; } } if (rawData != null) { TreeMap<String, String> map = new TreeMap<String, String>(); Iterator iter = rawData.keys(); while (iter.hasNext()) { String key = (String) iter.next(); Long onggg = (long) (Long.parseLong(key) * sampRate); // need to scale time appropriately for ecg leads Date time = new Date(onggg); String reportDate = df.format(time); //String shortKey = key.substring(5); Long numValue = (long) (Long.parseLong(rawData.getString(key)) * aduGain); String value = String.valueOf(numValue); map.put(reportDate, value); } int counterR = 0; for (Map.Entry<String, String> entry : map.entrySet()) { counterR++; String k = entry.getKey(); String v = entry.getValue(); finalDataString += "[" + k + "," + v + "],"; } System.out.println(":" + counterR + ": " + finalDataString); //System.out.println(":" + counterR + ": " + finalDataString); if (finalDataString.charAt(finalDataString.length() - 1) == ',') { finalDataString = finalDataString.substring(0, finalDataString.length() - 1); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return finalDataString; }
From source file:com.heliosapm.tsdblite.handlers.json.SplitTraceInputHandler.java
public String toHostObjectNameName(final ObjectName on) { final StringBuilder b = new StringBuilder("meta."); TreeMap<String, String> tgs = new TreeMap<String, String>(on.getKeyPropertyList()); final String metricName = on.getDomain(); String h = tgs.remove("host"); String a = tgs.remove("app"); final String host = h; //==null ? "*" : h; final String app = a == null ? "ANYAPP" : a; final int segIndex = metricName.indexOf('.'); final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex); if (host != null) { b.append(host).append(".").append(seg).append(":"); }//from w w w.j a va2 s. c o m if (app != null) { tgs.put("app", app); // b.append(app).append(".").append(seg).append(":"); } // if(segIndex!=-1) { // tgs.put("app", metricName.substring(segIndex+1)); // } for (Map.Entry<String, String> entry : tgs.entrySet()) { b.append(entry.getKey()).append("=").append(entry.getValue()).append(","); } b.deleteCharAt(b.length() - 1); return b.toString(); }