List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:com.sfs.whichdoctor.analysis.RevenueAnalysisDAOImpl.java
/** * Load stream revenue./*w ww .j av a 2 s. c o m*/ * * @param rs the rs * @return the revenue bean * @throws SQLException the sQL exception */ private RevenueBean loadStreamRevenue(final ResultSet rs) throws SQLException { final RevenueBean revenue = new RevenueBean(); revenue.setRevenueType(rs.getString("RevenueType")); revenue.setRevenueClass(rs.getString("RevenueClass")); revenue.setValue(rs.getDouble("RevenueValue")); revenue.setNetValue(rs.getDouble("RevenueNetValue")); final double gstRate = rs.getDouble("InvoiceGSTRate"); revenue.setGSTValue(gstRate, revenue.getGSTValue()); /** Temporary placeholder for Receipt details */ final ReceiptBean receipt = loadReceipt(rs); PaymentBean payment = new PaymentBean(); payment.setIncomeStream(rs.getString("RevenueType")); payment.setValue(rs.getDouble("RevenueValue")); payment.setNetValue(rs.getDouble("RevenueNetValue")); /* Load invoice details */ if (rs.getInt("InvoiceGUID") > 0) { payment.setDebit(loadDebit(rs)); } final Collection<PaymentBean> payments = new ArrayList<PaymentBean>(); payments.add(payment); receipt.setPayments(payments); TreeMap<Integer, ReceiptBean> receipts = new TreeMap<Integer, ReceiptBean>(); receipts.put(new Integer(receipt.getId()), receipt); revenue.setReceipts(receipts); return revenue; }
From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.CsvTable.java
public void createIndex(int column) { TreeMap<String, List<String[]>> index = new TreeMap<String, List<String[]>>(); for (String[] rec : table) { if (rec.length <= column) { continue; }/*from w w w.j ava 2 s . com*/ String n = rec[column]; List<String[]> el = index.get(n); if (el == null) { el = new ArrayList<String[]>(); index.put(n, el); } el.add(rec); } indices.put(column, index); }
From source file:com.sfs.whichdoctor.analysis.RevenueAnalysisDAOImpl.java
/** * Load batch revenue./*from www. j a v a 2 s . co m*/ * * @param rs the rs * @return the revenue bean * @throws SQLException the sQL exception */ private RevenueBean loadBatchRevenue(final ResultSet rs) throws SQLException { final RevenueBean revenue = new RevenueBean(); revenue.setBatchReference(rs.getInt("BatchReference")); revenue.setBatchNo(rs.getString("BatchNo")); if (revenue.getBatchNo() == null) { revenue.setBatchNo(rs.getString("BatchReference")); } if (revenue.getBatchNo().compareTo("") == 0) { revenue.setBatchNo(rs.getString("BatchReference")); } revenue.setValue(rs.getDouble("RevenueValue")); revenue.setNetValue(rs.getDouble("RevenueNetValue")); final double gstRate = rs.getDouble("InvoiceGSTRate"); revenue.setGSTValue(gstRate, revenue.getGSTValue()); /** Temporary placeholder for Receipt details */ ReceiptBean receipt = loadReceipt(rs); PaymentBean payment = new PaymentBean(); payment.setIncomeStream(rs.getString("RevenueType")); payment.setValue(rs.getDouble("RevenueValue")); payment.setNetValue(rs.getDouble("RevenueNetValue")); /* Load invoice details */ if (rs.getInt("InvoiceGUID") > 0) { payment.setDebit(loadDebit(rs)); } Collection<PaymentBean> payments = new ArrayList<PaymentBean>(); payments.add(payment); receipt.setPayments(payments); TreeMap<Integer, ReceiptBean> receipts = new TreeMap<Integer, ReceiptBean>(); receipts.put(new Integer(receipt.getId()), receipt); revenue.setReceipts(receipts); return revenue; }
From source file:io.github.jeddict.jpa.spec.sync.JavaClassSyncHandler.java
private void syncHeaderJavaDoc(TypeDeclaration<?> type) { TreeMap<Integer, Comment> comments = new TreeMap<>(); int packagePosition = 1; if (type.getParentNode().isPresent()) { Node parentNode = type.getParentNode().get(); parentNode.getComment().ifPresent(comment -> comments.put(comment.getBegin().get().line, comment)); for (Node node : parentNode.getChildNodes()) { if (node instanceof PackageDeclaration) { PackageDeclaration packageDeclaration = (PackageDeclaration) node; if (packageDeclaration.getBegin().isPresent()) { packagePosition = packageDeclaration.getBegin().get().line; }/* w ww . j a v a 2 s . c om*/ if (packageDeclaration.getComment().isPresent()) { Comment comment = packageDeclaration.getComment().get(); comments.put(comment.getBegin().get().line, comment); } } else if (node instanceof Comment) { Comment comment = (Comment) node; comments.put(comment.getBegin().get().line, comment); } } } type.getComment().ifPresent(comment -> comments.put(comment.getBegin().get().line, comment)); comments.headMap(packagePosition).values().forEach(this::syncHeader); comments.tailMap(packagePosition).values().forEach(this::syncJavadoc); }
From source file:com.heliosapm.tsdblite.metric.Metric.java
public ObjectName toHostObjectName() { final StringBuilder b = new StringBuilder("metrics."); TreeMap<String, String> tgs = new TreeMap<String, String>(tags); String h = tgs.remove("host"); String a = tgs.remove("app"); final String host = h == null ? "unknownhost" : h; final int segIndex = metricName.indexOf('.'); final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex); b.append(host).append(".").append(seg).append(":"); if (segIndex != -1) { tgs.put("app", metricName.substring(segIndex + 1)); }//from w ww. j a v a 2 s. c om for (Map.Entry<String, String> entry : tgs.entrySet()) { b.append(entry.getKey()).append("=").append(entry.getValue()).append(","); } b.deleteCharAt(b.length() - 1); return JMXHelper.objectName(b); }
From source file:com.facebook.tsdb.tsdash.server.model.Metric.java
public void alignAllTimeSeries() { long cycle = guessTimeCycle(); // wrap the time stamps to a multiple of cycle for (ArrayList<DataPoint> points : timeSeries.values()) { for (DataPoint p : points) { p.ts -= p.ts % cycle;/* w ww . ja v a 2 s .com*/ } } // do the actual aligning TreeMap<TagsArray, ArrayList<DataPoint>> aligned = new TreeMap<TagsArray, ArrayList<DataPoint>>( Tag.arrayComparator()); for (TagsArray header : timeSeries.keySet()) { aligned.put(header, TimeSeries.align(timeSeries.get(header), cycle)); } // align the time series between each other long maxmin = Long.MIN_VALUE; long minmax = Long.MAX_VALUE; long maxmax = Long.MIN_VALUE; for (ArrayList<DataPoint> points : aligned.values()) { if (points.size() == 0) { logger.error("We have found an empty timeseries"); continue; } DataPoint first = points.get(0); if (points.size() > 0 && points.get(0).ts > maxmin) { maxmin = first.ts; } DataPoint last = points.get(points.size() - 1); if (last.ts < minmax) { minmax = last.ts; } if (last.ts > maxmax) { maxmax = last.ts; } } if (maxmax - minmax > DATA_MISSING_THOLD) { // we've just detected missing data from this set of time series logger.error("Missing data detected"); // add padding to maxmax for (ArrayList<DataPoint> points : aligned.values()) { if (points.size() == 0) { continue; } long max = points.get(points.size() - 1).ts; for (long ts = max + cycle; ts <= maxmax; ts += cycle) { points.add(new DataPoint(ts, 0.0)); } } } else { // cut off the tail for (ArrayList<DataPoint> points : aligned.values()) { while (points.size() > 0 && points.get(points.size() - 1).ts > minmax) { points.remove(points.size() - 1); } } } // cut off the head for (ArrayList<DataPoint> points : aligned.values()) { while (points.size() > 0 && points.get(0).ts < maxmin) { points.remove(0); } } this.timeSeries = aligned; }
From source file:com.kaikoda.cah.CardGeneratorOptions.java
/** * Converts an array of arguments supplied at run-time, checks them for * validity and returns a the valid option data. * //from w w w . j av a 2s.c o m * @param args an unchecked list expressing option choices. * @return a valid list of the options chosen. * @throws ParseException if there are any problems encountered while * parsing the command line tokens. */ public TreeMap<String, String> parse(String[] args) throws ParseException { TreeMap<String, String> params = new TreeMap<String, String>(); // Parse runtime options from the command-line CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(this.options, args); // Check whether a level of verbosity has been specified if (line.hasOption("v")) { // Record the level specified params.put("verbosity", line.getOptionValue("v")); } // Check if help has been requested if (line.hasOption("h")) { // Provide help params.put("help", this.getHelp()); // No further processing required return params; } File inputLocation = null; File dictionaryLocation = null; String targetLanguage = null; String product = null; // Retrieve the input file if (line.hasOption("f")) { inputLocation = new File(line.getOptionValue("f")); } // Retrieve the dictionary if (line.hasOption("d")) { dictionaryLocation = new File(line.getOptionValue("d")); } // Retrieve the locale code if (line.hasOption("l")) { targetLanguage = line.getOptionValue("l"); } // Retrieve the product required if (line.hasOption("p")) { product = line.getOptionValue("p"); } // Check whether an input location has been specified (required). if (inputLocation == null) { throw new IllegalArgumentException("Nothing to process; no file or directory was specified."); } // Add the input location to the parsed option data. params.put("path-to-data", inputLocation.getAbsolutePath()); // Check whether a dictionary has been specified if (dictionaryLocation != null) { // Add the dictionary to the parsed option data params.put("path-to-dictionary", dictionaryLocation.getAbsolutePath()); } // Check whether a target language has been specified. if (targetLanguage != null) { // Add the target language to the parsed option data params.put("output-language", targetLanguage); } // Check whether a product has been specified if (product != null) { // Add the product to the parsed option data params.put("product", product); } // Return the parsed option data return params; }
From source file:edu.umass.cs.gigapaxos.paxospackets.PrepareReplyPacket.java
private TreeMap<Integer, PValuePacket> parseJsonForAccepted(JSONObject json) throws JSONException { TreeMap<Integer, PValuePacket> accepted = new TreeMap<Integer, PValuePacket>(); if (json.has(PaxosPacket.Keys.ACC_MAP.toString())) { JSONArray jsonArray = json.getJSONArray(PaxosPacket.Keys.ACC_MAP.toString()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject element = jsonArray.getJSONObject(i); PValuePacket pval = new PValuePacket(element); accepted.put(pval.slot, pval); }/*from w w w. ja va 2s. c o m*/ } return accepted; }
From source file:com.celements.navigation.service.TreeNodeService.java
/** * fetchNodesForParentKey/* w w w .ja v a 2 s.com*/ * @param parentKey * @param context * @return Collection keeps ordering of TreeNodes according to posId */ List<TreeNode> fetchNodesForParentKey(EntityReference parentRef) { String parentKey = getParentKey(parentRef, true); LOGGER.trace("fetchNodesForParentKey: parentRef [" + parentRef + "] parentKey [" + parentKey + "]."); long starttotal = System.currentTimeMillis(); long start = System.currentTimeMillis(); List<TreeNode> nodes = fetchNodesForParentKey_internal(parentKey, starttotal, start); if ((nodeProviders != null) && (nodeProviders.values().size() > 0)) { TreeMap<Integer, TreeNode> treeNodesMergedMap = new TreeMap<Integer, TreeNode>(); for (TreeNode node : nodes) { treeNodesMergedMap.put(new Integer(node.getPosition()), node); } for (ITreeNodeProvider tnProvider : nodeProviders.values()) { try { for (TreeNode node : tnProvider.getTreeNodesForParent(parentKey)) { treeNodesMergedMap.put(new Integer(node.getPosition()), node); } } catch (Exception exp) { LOGGER.warn("Failed on provider [" + tnProvider.getClass() + "] to get nodes for parentKey [" + parentKey + "].", exp); } } nodes = new ArrayList<TreeNode>(treeNodesMergedMap.values()); long end = System.currentTimeMillis(); LOGGER.info("fetchNodesForParentKey: [" + parentKey + "] totaltime for list of [" + nodes.size() + "]: " + (end - starttotal)); } return nodes; }
From source file:com.l2jfree.sql.L2DatabaseInstaller.java
public static void check() throws SAXException, IOException, ParserConfigurationException { final TreeMap<String, String> tables = new TreeMap<String, String>(); final TreeMap<Double, String> updates = new TreeMap<Double, String>(); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); // FIXME add validation factory.setIgnoringComments(true);//from w w w .j a v a 2 s. co m final List<Document> documents = new ArrayList<Document>(); InputStream is = null; try { // load default database schema from resources is = L2DatabaseInstaller.class.getResourceAsStream("database_schema.xml"); documents.add(factory.newDocumentBuilder().parse(is)); } finally { IOUtils.closeQuietly(is); } final File f = new File("./config/database_schema.xml"); // load optional project specific database tables/updates (fails on already existing) if (f.exists()) documents.add(factory.newDocumentBuilder().parse(f)); for (Document doc : documents) { for (Node n1 : L2XML.listNodesByNodeName(doc, "database")) { for (Node n2 : L2XML.listNodesByNodeName(n1, "table")) { final String name = L2XML.getAttribute(n2, "name"); final String definition = L2XML.getAttribute(n2, "definition"); final String oldDefinition = tables.put(name, definition); if (oldDefinition != null) throw new RuntimeException("Found multiple tables with name " + name + "!"); } for (Node n2 : L2XML.listNodesByNodeName(n1, "update")) { final Double revision = Double.valueOf(L2XML.getAttribute(n2, "revision")); final String query = L2XML.getAttribute(n2, "query"); final String oldQuery = updates.put(revision, query); if (oldQuery != null) throw new RuntimeException("Found multiple updates with revision " + revision + "!"); } } } createRevisionTable(); final double databaseRevision = getDatabaseRevision(); if (databaseRevision == -1) // no table exists { for (Entry<String, String> table : tables.entrySet()) { final String tableName = table.getKey(); final String tableDefinition = table.getValue(); installTable(tableName, tableDefinition); } if (updates.isEmpty()) insertRevision(0); else insertRevision(updates.lastKey()); } else // check for possibly required updates { for (Entry<String, String> table : tables.entrySet()) { final String tableName = table.getKey(); final String tableDefinition = table.getValue(); if (L2Database.tableExists(tableName)) continue; System.err.println("Table '" + tableName + "' is missing, so the server attempts to install it."); System.err.println("WARNING! It's highly recommended to check the results manually."); installTable(tableName, tableDefinition); } for (Entry<Double, String> update : updates.entrySet()) { final double updateRevision = update.getKey(); final String updateQuery = update.getValue(); if (updateRevision > databaseRevision) { executeUpdate(updateQuery); insertRevision(updateRevision); } } } }