List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:com.sfs.beans.PrivilegesBean.java
/** * Generates a JDOM Document form the values set in this PrivilegesBean. * * @return JDOM element representing the privilege values *//* ww w .ja v a 2 s.co m*/ public final Document getXmlDocument() { Element rootElement = new Element("privileges"); TreeMap<String, RoleBean> roleMap = this.getRoles(); for (String roleName : roleMap.keySet()) { RoleBean role = (RoleBean) roleMap.get(roleName); if (role != null) { Element userclass = new Element("userClass"); Element name = new Element("name").setText(role.getName()); Element description = new Element("description").setText(role.getDescription()); Element emailName = new Element("emailName").setText(role.getEmailName()); Element emailAddress = new Element("emailAddress").setText(role.getEmailAddress()); Element actions = new Element("actions"); userclass.addContent(name); userclass.addContent(description); userclass.addContent(emailName); userclass.addContent(emailAddress); TreeMap<String, PrivilegeBean> privilegeRoles = role.getPrivileges(); for (String privilegeName : privilegeRoles.keySet()) { PrivilegeBean privilege = (PrivilegeBean) privilegeRoles.get(privilegeName); if (privilege != null) { Element action = new Element("action").setText(privilege.getName()); ArrayList<Attribute> attributes = new ArrayList<Attribute>(); String strCreate = "false"; String strModify = "false"; String strDelete = "false"; if (privilege.getCreate()) { strCreate = "true"; } if (privilege.getModify()) { strModify = "true"; } if (privilege.getDelete()) { strDelete = "true"; } Attribute create = new Attribute("create", strCreate); Attribute modify = new Attribute("modify", strModify); Attribute delete = new Attribute("delete", strDelete); attributes.add(create); attributes.add(modify); attributes.add(delete); action.setAttributes(attributes); actions.addContent(action); } } userclass.addContent(actions); rootElement.addContent(userclass); } } return new Document(rootElement); }
From source file:gsn.vsensor.ChartVirtualSensor.java
public boolean initialize() { /**// w ww. j ava 2 s .c o m * TODO : Checking if the user provides the arguements currectly. TODO : * This can now plot only for one input stream value. */ TreeMap<String, String> params = getVirtualSensorConfiguration().getMainClassInitialParams(); String size = params.get("history-size"); ChartInfo chartInfo = new ChartInfo(); if (size == null) { chartInfo.setHistorySize(10); chartInfo.setHistoryIsTime(false); } else { Pair<Boolean, Long> p = Utils.parseWindowSize(size); chartInfo.setHistorySize(p.getSecond().intValue()); chartInfo.setHistoryIsTime(p.getFirst()); } chartInfo.setInputStreamName(params.get("input-stream")); // logger.debug("All keys "+params.keySet().iterator().next()); chartInfo.setPlotTitle(params.get("title")); chartInfo.setType(params.get("type")); chartInfo.setHeight(ParamParser.getInteger(params.get("height"), 480)); chartInfo.setWidth(ParamParser.getInteger(params.get("width"), 640)); chartInfo.setVerticalAxisTitle(params.get("vertical-axis")); input_stream_name_to_ChartInfo_map.put(chartInfo.getInputStreamName(), chartInfo); chartInfo.initialize(); return true; }
From source file:ANNFileDetect.EncogTestClass.java
private void createReport(TreeMap<Double, Integer> ht, String file) throws IOException { TreeMap<Integer, ArrayList<Double>> tm = new TreeMap<Integer, ArrayList<Double>>(); for (Map.Entry<Double, Integer> entry : ht.entrySet()) { if (tm.containsKey(entry.getValue())) { ArrayList<Double> al = (ArrayList<Double>) tm.get(entry.getValue()); al.add(entry.getKey());/* w w w . j ava 2 s . co m*/ tm.put(entry.getValue(), al); } else { ArrayList<Double> al = new ArrayList<Double>(); al.add(entry.getKey()); tm.put(entry.getValue(), al); } } String[] tmpfl = file.split("/"); if (tmpfl.length < 2) tmpfl = file.split("\\\\"); String crp = tmpfl[tmpfl.length - 1]; String[] actfl = crp.split("\\."); FileWriter fstream = new FileWriter("tempTrainingFiles/" + actfl[1].toUpperCase() + actfl[0] + ".txt"); BufferedWriter fileto = new BufferedWriter(fstream); int size = tm.size(); int cnt = 0; for (Map.Entry<Integer, ArrayList<Double>> entry : tm.entrySet()) { if (cnt > (size - 10) && entry.getKey() > 2 && entry.getValue().size() < 20) { double tmpval = ((double) entry.getKey()) / filebytes; fileto.write("Times: " + tmpval + " Values: "); for (Double dbl : entry.getValue()) { fileto.write(dbl + " "); } fileto.write("\n"); } cnt++; } fileto.close(); }
From source file:gsn.vsensor.DataCleanVirtualSensor.java
public boolean initialize() { TreeMap<String, String> params = getVirtualSensorConfiguration().getMainClassInitialParams(); String model_str = params.get(PARAM_MODEL); if (model_str == null) { logger.warn("Parameter \"" + PARAM_MODEL + "\" not provided in Virtual Sensor file"); return false; } else {/* w w w. j a v a 2s . c o m*/ model = getModelIdFromString(model_str.trim()); if (model == -1) { logger.warn("Parameter \"" + PARAM_MODEL + "\" incorrect in Virtual Sensor file"); return false; } } String window_size_str = params.get(PARAM_WINDOW_SIZE); if (window_size_str == null) { logger.warn("Parameter \"" + PARAM_WINDOW_SIZE + "\" not provided in Virtual Sensor file"); return false; } else try { window_size = Integer.parseInt(window_size_str.trim()); } catch (NumberFormatException e) { logger.warn("Parameter \"" + PARAM_WINDOW_SIZE + "\" incorrect in Virtual Sensor file"); return false; } if (window_size < 0) { logger.warn("Window size should always be positive."); return false; } String error_bound_str = params.get(PARAM_ERROR_BOUND); if (error_bound_str == null) { logger.warn("Parameter \"" + PARAM_ERROR_BOUND + "\" not provided in Virtual Sensor file"); return false; } else try { error_bound = Double.parseDouble(error_bound_str.trim()); } catch (NumberFormatException e) { logger.warn("Parameter \"" + PARAM_ERROR_BOUND + "\" incorrect in Virtual Sensor file"); return false; } metadata_server_url = params.get(PARAM_METADATA_SERVER); if (metadata_server_url != null) { publish_to_metadata_server = true; username = params.get(PARAM_METADATA_USERNAME); password = params.get(PARAM_METADATA_PASSWORD); if (username != null && password != null) metadata_server_requieres_password = true; operator = params.get(PARAM_METADATA_OPERATOR); deployement = params.get(PARAM_METADATA_DEPLOYEMENT); station = params.get(PARAM_METADATA_STATION); sensor = params.get(PARAM_METADATA_SENSOR); if ((operator == null) || (deployement == null) || (station == null) || (sensor == null)) { logger.warn( "A parameter required for publishing metadata is missing. Couldn't publish to metadata server."); publish_to_metadata_server = false; } else { prepared_xml_request = xml_template.replaceAll(OPERATOR, operator); prepared_xml_request = prepared_xml_request.replaceAll(DEPLOYMENT, deployement); prepared_xml_request = prepared_xml_request.replaceAll(STATION, station); prepared_xml_request = prepared_xml_request.replaceAll(SENSOR, sensor); } } stream = new double[window_size]; timestamps = new long[window_size]; processed = new double[window_size]; dirtiness = new double[window_size]; quality = new double[window_size]; String logging_interval_str = params.get(PARAM_LOGGING_INTERVAL); if (logging_interval_str != null) { logging_timestamps = true; try { logging_interval = Integer.parseInt(logging_interval_str.trim()); } catch (NumberFormatException e) { logger.warn("Parameter \"" + PARAM_LOGGING_INTERVAL + "\" incorrect in Virtual Sensor file"); logging_timestamps = false; } } return true; }
From source file:gsn.wrappers.general.CSVWrapperTest.java
@Test public void testFieldConverting() throws IOException { String fields = "TIMED, air_temp , TIMED , AiR_TeMp2"; String formats = "Timestamp(d.M.y ) , Numeric , timestamp(k:m) , numeric "; String badFormat = "Timestamp(d.M.y k:m) , numeric , numeric, numeric,numeric,dollluble "; String badFormat2 = "Timestamp(d.Mjo0o.y k:m) , numeric, numeric, numeric"; CSVHandler wrapper = new CSVHandler(); assertEquals(false, wrapper.initialize("test.csv.csv", fields, badFormat, ',', '\"', 0, "NaN,-1234,4321")); assertEquals(false, wrapper.initialize("test.csv.csv", fields, badFormat, ',', '\"', 0, "NaN,-1234,4321")); assertEquals(false, wrapper.initialize("test.csv.csv", fields, badFormat2, ',', '\"', 0, "NaN,-1234,4321")); assertEquals(true, wrapper.initialize("test.csv.csv", fields, formats, ',', '\"', 0, "NaN,-1234,4321")); FileUtils.writeStringToFile(new File(wrapper.getCheckPointFile()), "", "UTF-8"); String[] formatsParsed = wrapper.getFormats(); String[] fieldsParsed = wrapper.getFields(); assertEquals(true, compare(fieldsParsed, new String[] { "timed", "air_temp", "timed", "air_temp2" })); assertEquals(true, compare(formatsParsed, new String[] { "Timestamp(d.M.y )", "Numeric", "timestamp(k:m)", "numeric" })); TreeMap<String, Serializable> se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] {}, wrapper.getSeparator()); assertEquals(wrapper.getFields().length - 1, se.keySet().size());//timestamp is douplicated. assertEquals(null, se.get("timed")); se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] { "", "", "", "-1234", "4321", "NaN" }, wrapper.getSeparator()); assertEquals(null, se.get("timed")); se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] { "", "", "", "-1234", "4321", "NaN" }, wrapper.getSeparator()); assertEquals(null, se.get("timed")); se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] { "01.01.2009", "1234", "", "-4321", "ignore-me", "NaN" }, wrapper.getSeparator()); long parsedTimestamp = (Long) se.get("timed"); assertEquals(true, parsedTimestamp > 0); assertEquals(1234.0, se.get("air_temp")); assertEquals(-4321.0, se.get("air_temp2")); se = wrapper.convertTo(wrapper.getFormats(), wrapper.getFields(), wrapper.getNulls(), new String[] { "01.01.2009", "-1234", "10:10", "-4321", "ignore-me", "NaN" }, wrapper.getSeparator());//from www. ja v a 2 s . co m assertEquals(true, ((Long) se.get("timed")) > parsedTimestamp); assertNull(se.get("air_temp")); }
From source file:dreamboxdataservice.DreamboxDataService.java
/** * @return All channels available in the dreambox *//*from www . jav a 2s. c o m*/ public ArrayList<Channel> getChannels() { try { ArrayList<Channel> allChannels = new ArrayList<Channel>(); TreeMap<String, String> bouquets = getServiceDataBonquets(URLEncoder.encode(BOUQUETLIST, "UTF8")); if (bouquets != null) { for (String key : bouquets.keySet()) { TreeMap<String, String> map = getServiceData(URLEncoder.encode(key, "UTF8")); for (String mkey : map.keySet()) { Channel ch = new Channel(this, map.get(mkey), "DREAM" + StringUtils.replace(mkey, ":", "_"), TimeZone.getTimeZone("GMT+1:00"), "de", "Imported from Dreambox", "", mChannelGroup, null, Channel.CATEGORY_TV); allChannels.add(ch); } } } return allChannels; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return new ArrayList<Channel>(); }
From source file:org.apache.hadoop.mrunit.MapReduceDriverBase.java
/** Take the outputs from the Mapper, combine all values for the * same key, and sort them by key.//from w ww . ja v a 2 s .c o m * @param mapOutputs An unordered list of (key, val) pairs from the mapper * @return the sorted list of (key, list(val))'s to present to the reducer */ public List<Pair<K2, List<V2>>> shuffle(List<Pair<K2, V2>> mapOutputs) { // step 1 - use the key group comparator to organise map outputs final TreeMap<K2, List<Pair<K2, V2>>> groupedByKey = new TreeMap<K2, List<Pair<K2, V2>>>( keyGroupComparator); List<Pair<K2, V2>> groupedKeyList; for (Pair<K2, V2> mapOutput : mapOutputs) { groupedKeyList = groupedByKey.get(mapOutput.getFirst()); if (groupedKeyList == null) { groupedKeyList = new ArrayList<Pair<K2, V2>>(); groupedByKey.put(mapOutput.getFirst(), groupedKeyList); } groupedKeyList.add(mapOutput); } // step 2 - sort each key group using the key order comparator (if set) Comparator<Pair<K2, V2>> pairKeyComparator = new Comparator<Pair<K2, V2>>() { @Override public int compare(Pair<K2, V2> o1, Pair<K2, V2> o2) { return keyValueOrderComparator.compare(o1.getFirst(), o2.getFirst()); } }; // create shuffle stage output list List<Pair<K2, List<V2>>> outputKeyValuesList = new ArrayList<Pair<K2, List<V2>>>(); // populate output list for (Entry<K2, List<Pair<K2, V2>>> groupedByKeyEntry : groupedByKey.entrySet()) { if (keyValueOrderComparator != null) { // sort the key/value pairs using the key order comparator (if set) Collections.sort(groupedByKeyEntry.getValue(), pairKeyComparator); } // create list to hold values for the grouped key List<V2> valuesList = new ArrayList<V2>(); for (Pair<K2, V2> pair : groupedByKeyEntry.getValue()) { valuesList.add(pair.getSecond()); } // add key and values to output list outputKeyValuesList.add(new Pair<K2, List<V2>>(groupedByKeyEntry.getKey(), valuesList)); } // return output list return outputKeyValuesList; }
From source file:org.apache.hadoop.raid.TestRaidHistogram.java
public void printBlockFixStatus(TreeMap<Long, BlockFixStatus> status) { for (Long window : status.keySet()) { LOG.info("Window: " + window); BlockFixStatus bfs = status.get(window); LOG.info("failedPaths: " + bfs.failedPaths); String values = ""; for (Long val : bfs.percentValues) { values += "/" + val; }//from w ww .ja v a 2 s . c om LOG.info("percentValues: " + values); } }
From source file:org.posterita.businesslogic.performanceanalysis.CustomPOSReportManager.java
public static TabularReport generateTabularReportGroupByDate(Properties ctx, String title, String subtitle, int account_id, Timestamp fromDate, Timestamp toDate, String salesGroup, String priceQtyFilter) throws OperationException { boolean isTaxDue = (account_id == Constants.TAX_DUE.intValue()); boolean isTaxCredit = (account_id == Constants.TAX_CREDIT.intValue()); NumberFormat formatter = new DecimalFormat("###,###,##0.00"); String sql = SalesAnalysisReportManager.getTabularDataSetSQL(ctx, account_id, fromDate, toDate, salesGroup); ArrayList<Object[]> tmpData = ReportManager.getReportData(ctx, sql, true); String currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol(); ArrayList<Object[]> reportData = new ArrayList<Object[]>(); Object[] data = null;/*from w ww . j ava 2 s . co m*/ BigDecimal b = null; if (isTaxCredit || isTaxDue) { reportData.add(tmpData.remove(0)); Iterator<Object[]> iter = tmpData.iterator(); while (iter.hasNext()) { data = iter.next(); if (data.length == 1) { b = (BigDecimal) data[0]; data[0] = formatter.format(b.doubleValue()); } reportData.add(data); } } else { //---------------------------------------------------------------------------------------------------------------------------------------------------------- TreeMap<String, TabularReportRecordBean> map = new TreeMap<String, TabularReportRecordBean>(); String productName = null; BigDecimal price = null; BigDecimal qty = null; TabularReportRecordBean bean = null; ArrayList<Object[]> reportData2 = new ArrayList<Object[]>(); Object[] headers = tmpData.remove(0); //adding headers reportData2.add(new Object[] { headers[0], //headers[1], headers[2] + "(" + currency + ")", headers[3] }); double totalAmt = 0.0d; int totalQty = 0; for (Object[] record : tmpData) { productName = (String) record[0]; price = (BigDecimal) record[2]; qty = (BigDecimal) record[3]; totalAmt += price.doubleValue(); totalQty += qty.intValue(); bean = map.get(productName); if (bean == null) { bean = new TabularReportRecordBean(); bean.setProductName(productName); bean.setDate(""); bean.setPrice(price); bean.setQty(qty); } else { bean.setPrice(bean.getPrice().add(price)); bean.setQty(bean.getQty().add(qty)); } map.put(productName, bean); } //for Collection<TabularReportRecordBean> c = map.values(); for (TabularReportRecordBean tbean : c) { Object[] obj = new Object[] { tbean.getProductName(), tbean.getPrice(), tbean.getQty() }; reportData2.add(obj); } reportData.add(reportData2.remove(0)); Iterator<Object[]> iter = reportData2.iterator(); while (iter.hasNext()) { data = iter.next(); if (data.length > 2) { b = (BigDecimal) data[1]; data[1] = formatter.format(b.doubleValue()); } reportData.add(data); } reportData.add(new Object[] { "Total", "" + formatter.format(totalAmt), totalQty + "" }); } //style for table String tableStyle = "display"; //style for columns String[] styles = new String[] { "string", "currency", "numeric" }; if (isTaxCredit || isTaxDue) { styles = new String[] { "numeric" }; } //constructing the table TabularReport tReport = new TabularReport(reportData); //tReport.setSortable(true); tReport.setHeaderStyle(styles); tReport.setStyle(tableStyle); tReport.setTitle(title); tReport.setSubtitle(subtitle); tReport.createReport(); return tReport; }
From source file:com.masse.mvn.plugin.BuildJsonFromPropertiesMojo.java
private StringBuffer PrintJsonTree(TreeMap<String, PropertiesToJson> tm, int indent, boolean hasNext) { StringBuffer sb = new StringBuffer(); sb.append("{"); Iterator<String> itr = tm.keySet().iterator(); while (itr.hasNext()) { PropertiesToJson ptj = tm.get(itr.next()); if (ptj.getValue() != null) { sb.append("\"" + ptj.getJsonKey() + "\"" + ":" + "\"" + escapingQuote(ptj.getValue()) + "\""); if (itr.hasNext()) sb.append(","); } else {//from w ww .ja v a2 s .c o m sb.append("\"" + ptj.getJsonKey() + "\"" + ":"); sb.append(PrintJsonTree(ptj.getChildren(), indent + 1, itr.hasNext())); } } if (hasNext) { sb.append("},"); } else { sb.append("}"); } return sb; }