List of usage examples for java.util TreeMap size
int size
To view the source code for java.util TreeMap size.
Click Source Link
From source file:com.github.benyzhous.springboot.web.core.gateway.sign.backend.Sign.java
/** * Uri+???// w ww . j a va 2 s.c om * * @param uri HTTPuri,??Query * @param paramsMap HTTP?Query+Form? * @return Uri+??? */ private static String buildResource(String uri, Map<String, Object> paramsMap) { StringBuilder builder = new StringBuilder(); // uri builder.append(uri); // Query+Form TreeMap<String, Object> sortMap = new TreeMap<String, Object>(); sortMap.putAll(paramsMap); // Query+Form? if (sortMap.size() > 0) { builder.append('?'); builder.append(buildMapToSign(sortMap)); } return builder.toString(); }
From source file:com.sfs.whichdoctor.xml.writer.helper.AccreditationXmlHelper.java
/** * Output the training summary as an XML string. * * @param trainingSummary the training summary * @param type the type// w w w. j a v a 2 s .c o m * * @return the xml string */ public static String getSummaryXml(final TreeMap<String, AccreditationBean[]> trainingSummary, final String type) { final XmlWriter xmlwriter = new XmlWriter(); if (trainingSummary.size() > 0) { int totalCore = 0; int totalNonCore = 0; TreeMap<String, ArrayList<AccreditationBean[]>> summaryTreemap = new TreeMap<String, ArrayList<AccreditationBean[]>>(); for (String summaryKey : trainingSummary.keySet()) { AccreditationBean[] details = trainingSummary.get(summaryKey); AccreditationBean core = details[0]; AccreditationBean nonCore = details[1]; totalCore += core.getWeeksCertified(); totalNonCore += nonCore.getWeeksCertified(); if (StringUtils.isNotBlank(core.getSpecialtyType())) { ArrayList<AccreditationBean[]> summaries = new ArrayList<AccreditationBean[]>(); if (!summaryTreemap.containsKey(core.getSpecialtyType())) { /* New type of specialty */ summaries.add(details); } else { /* Existing specialty */ summaries = summaryTreemap.get(core.getSpecialtyType()); summaries.add(details); } summaryTreemap.put(core.getSpecialtyType(), summaries); } } xmlwriter.writeEntity("trainingSummary"); xmlwriter.writeAttribute("type", type); xmlwriter.writeAttribute("totalCore", Formatter.getWholeMonths(totalCore)); xmlwriter.writeAttribute("totalNonCore", Formatter.getWholeMonths(totalNonCore)); xmlwriter.writeEntity("specialtyTraining"); for (String specialtyType : summaryTreemap.keySet()) { ArrayList<AccreditationBean[]> summaries = summaryTreemap.get(specialtyType); int typeCoreWeeks = 0; int typeNCWeeks = 0; if (summaries != null) { // For each accredited specialty create an element xmlwriter.writeEntity("specialty"); xmlwriter.writeEntity("subtypes"); String division = ""; String abbreviation = ""; String specialtytype = ""; String typeAbbreviation = ""; for (Object[] summary : summaries) { boolean blSubType = false; AccreditationBean core = (AccreditationBean) summary[0]; AccreditationBean nonCore = (AccreditationBean) summary[1]; division = core.getAccreditationClass(); abbreviation = core.getAbbreviation(); specialtytype = core.getSpecialtyType(); typeAbbreviation = core.getSpecialtyTypeAbbreviation(); if (StringUtils.isNotBlank(core.getSpecialtySubType())) { blSubType = true; xmlwriter.writeEntity("subtype"); xmlwriter.writeEntity("name").writeText(core.getSpecialtySubType()).endEntity(); xmlwriter.writeEntity("coreMonths") .writeText(Formatter.getWholeMonths(core.getWeeksCertified())).endEntity(); xmlwriter.writeEntity("nonCoreMonths") .writeText(Formatter.getWholeMonths(nonCore.getWeeksCertified())).endEntity(); xmlwriter.endEntity(); typeCoreWeeks += core.getWeeksCertified(); typeNCWeeks += nonCore.getWeeksCertified(); } if (!blSubType) { xmlwriter.writeEntity("subtype"); xmlwriter.writeEntity("coreMonths") .writeText(Formatter.getWholeMonths(core.getWeeksCertified())).endEntity(); xmlwriter.writeEntity("nonCoreMonths") .writeText(Formatter.getWholeMonths(nonCore.getWeeksCertified())).endEntity(); xmlwriter.endEntity(); typeCoreWeeks += core.getWeeksCertified(); typeNCWeeks += nonCore.getWeeksCertified(); } } xmlwriter.endEntity(); xmlwriter.writeEntity("division").writeText(division).endEntity(); xmlwriter.writeEntity("abbreviation").writeText(abbreviation).endEntity(); xmlwriter.writeEntity("type").writeText(specialtytype).endEntity(); xmlwriter.writeEntity("typeAbbreviation").writeText(typeAbbreviation).endEntity(); xmlwriter.writeEntity("coreMonths").writeText(Formatter.getWholeMonths(typeCoreWeeks)) .endEntity(); xmlwriter.writeEntity("nonCoreMonths").writeText(Formatter.getWholeMonths(typeNCWeeks)) .endEntity(); xmlwriter.endEntity(); } } xmlwriter.endEntity(); xmlwriter.endEntity(); } return xmlwriter.getXml(); }
From source file:org.esxx.Response.java
static private void writeCSVRow(Context cx, CSVWriter csv, TreeMap<String, Integer> columns, Object r) { KeyValueWrapper row = new KeyValueWrapper(r); String[] fields = new String[columns.size()]; for (Object c : row.getKeys()) { int idx = columns.get(StringUtil.toSortable(c)); // System.out.println("Column " + Context.toString(c) + " has index " + idx); // System.out.println(Context.toString(row.getValue(cx, c))); fields[idx] = Context.toString(row.getValue(cx, c)); }//from w w w. j a va 2 s . c o m csv.writeNext(fields); }
From source file:org.kalypso.gml.ui.internal.coverage.CoverageColormapHandler.java
private static List<PolygonColorMapEntry> translateColormap( final TreeMap<Double, ColorMapEntry> newRasterColorMap) { /* Translate raster colormap to polygon colormap with same classification */ final List<PolygonColorMapEntry> newPolygonColorMap = new ArrayList<>(newRasterColorMap.size()); Entry<Double, ColorMapEntry> lastEntry = null; for (final Entry<Double, ColorMapEntry> entry : newRasterColorMap.entrySet()) { if (lastEntry != null) { final ColorMapEntry value = entry.getValue(); final Color color = value.getColorAndOpacity(); final BigDecimal fromValue = new BigDecimal(lastEntry.getValue().getQuantity()); final BigDecimal toValue = new BigDecimal(entry.getValue().getQuantity()); final PolygonColorMapEntry newEntry = StyleFactory.createPolygonColorMapEntry(color, color, fromValue, toValue); // REMARK: always use width '2': hides ugly artifacts in map (because fill and outline do not exactly match). newEntry.getStroke().setWidth(2); // TODO: use should decide if triangles are visible (no stroke, faster), or hidden (stroke with same color), // slower. newPolygonColorMap.add(newEntry); }//from ww w . j a va 2 s . c o m lastEntry = entry; } return newPolygonColorMap; }
From source file:spec.reporter.Utils.java
public static void generateMainChart(double compositeScore, TreeMap<String, Double> scores) { // Valid benchmarks + room for all possible extra - compiler, crypto, scimark, scimark.small, scimark.large, startup, xml, composite score Color[] colors = new Color[scores.size() + 8]; // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int count = 0; Iterator<String> iteratorBenchmarks = scores.keySet().iterator(); while (iteratorBenchmarks.hasNext()) { String key = iteratorBenchmarks.next(); Double score = scores.get(key); if (Utils.isValidScore(score)) { dataset.addValue(score, key, key); colors[count++] = (Color) colorMap.get(key); }/*from w w w . java2 s. com*/ } if (Utils.isValidScore(compositeScore)) { dataset.addValue(compositeScore, Utils.CSCORE_NAME, Utils.CSCORE_NAME); colors[count++] = (Color) colorMap.get(Utils.CSCORE_NAME); } JFreeChart chart = ChartFactory.createStackedBarChart("Scores", // chart title "", // domain axis label "", dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend false, // tooltips? false // URLs? ); CategoryItemRenderer renderer = chart.getCategoryPlot().getRendererForDataset(dataset); for (int i = 0; i < count; i++) { Color paint = (Color) colors[i]; if (paint != null) { renderer.setSeriesPaint(i, paint); } } try { ChartUtilities.saveChartAsJPEG(new File(getFullImageName("all")), chart, 600, 50 + (dataset.getRowCount()) * 20); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * @param r/*from ww w .ja v a2 s . co m*/ * the original rectangle * @param includeReservedInsets * if taskbar and other windowing insets should be included in the * returned area * @return iff there are multiple monitors the other monitor than the * effective view of the monitor that the rectangle mostly coveres, or * null if there is just one screen */ public static Rectangle getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); TreeMap<Integer, Rectangle> prioMap = new TreeMap<Integer, Rectangle>(); for (GraphicsDevice dev : ge.getScreenDevices()) { Rectangle bounds; if ((!includeReservedInsets) && dev == ge.getDefaultScreenDevice()) { bounds = ge.getMaximumWindowBounds(); } else { bounds = dev.getDefaultConfiguration().getBounds(); } Rectangle intersection = bounds.intersection(r); prioMap.put(intersection.width * intersection.height, bounds); } if (prioMap.size() <= 1) { return null; } else { return prioMap.get(prioMap.firstKey()); } }
From source file:com.ebay.erl.mobius.core.model.TupleColumnComparator.java
private static int compare(TreeMap<String, String> m1, TreeMap<String, String> m2) { int _COMPARE_RESULT = Integer.MAX_VALUE; int m1_size = m1.size(); int m2_size = m2.size(); if (m1_size == 0 || m2_size == 0) { if (m1_size == m2_size) return 0; else if (m1_size != 0) return 1; else//ww w.j a va2 s . co m return -1; } Iterator<String> k1_it = m1.keySet().iterator(); Iterator<String> k2_it = m2.keySet().iterator(); boolean hasDiff = false; while (k1_it.hasNext()) { String k1 = k1_it.next(); if (k2_it.hasNext()) { String k2 = k2_it.next(); _COMPARE_RESULT = String.CASE_INSENSITIVE_ORDER.compare(k1, k2); if (_COMPARE_RESULT == 0) { // same key, check their value String v1 = m1.get(k1); String v2 = m2.get(k2); _COMPARE_RESULT = v1.compareTo(v2); } } else { // m1 has more keys than m2 and m1 has the same // values for all the keys in m2 _COMPARE_RESULT = 1; } if (_COMPARE_RESULT != 0 && _COMPARE_RESULT != Integer.MAX_VALUE) { hasDiff = true; break;// has result } } if (!hasDiff) { if (k2_it.hasNext()) { // m2 has more keys than m1, and m2 has the same // values for all the keys in m1 _COMPARE_RESULT = -1; } else { // m1 and m2 are the same } } return _COMPARE_RESULT; }
From source file:net.triptech.buildulator.DataParser.java
/** * Parses the text data.// w w w . ja va2 s.c o m * * @param text the text * * @return the tree map< integer, tree map< integer, string>> */ public static String[][] parseTextData(final String text) { TreeMap<Integer, TreeMap<Integer, String>> rowData = new TreeMap<Integer, TreeMap<Integer, String>>(); // This counter holds the maximum number of columns provided int maxNumberOfTokens = 0; if (text != null) { BufferedReader in = new BufferedReader(new StringReader(text)); String line; int lineCounter = 0; try { while ((line = in.readLine()) != null) { TreeMap<Integer, String> parsedLine = new TreeMap<Integer, String>(); SmartTokenizer tabTokenizer = new SmartTokenizer(line, "\t"); if (tabTokenizer.countTokens() > 1) { parsedLine = tokenizerToMap(tabTokenizer); } else { SmartTokenizer commaTokenizer = new SmartTokenizer(line, ","); parsedLine = tokenizerToMap(commaTokenizer); } if (parsedLine.size() > maxNumberOfTokens) { maxNumberOfTokens = parsedLine.size(); } rowData.put(lineCounter, parsedLine); lineCounter++; } } catch (IOException ioe) { // Error reading string } } String[][] parsedData = new String[rowData.size()][]; // Now cycle through all the parsed data // Ensure that each row has the same (max) number of tokens for (int rowIndex : rowData.keySet()) { TreeMap<Integer, String> parsedLine = rowData.get(rowIndex); // This map holds the final values TreeMap<Integer, String> columnTokens = new TreeMap<Integer, String>(); for (int i = 0; i < maxNumberOfTokens; i++) { String value = ""; if (parsedLine.containsKey(i)) { value = parsedLine.get(i); } columnTokens.put(i, value); } parsedData[rowIndex] = new String[columnTokens.size()]; for (int columnIndex : columnTokens.keySet()) { String value = columnTokens.get(columnIndex); parsedData[rowIndex][columnIndex] = value; } } return parsedData; }
From source file:org.apdplat.superword.tools.SentenceScorer.java
public static void toTextFile(TreeMap<Float, Map<String, List<String>>> scores, String fileName) { LOGGER.debug("" + fileName); AtomicInteger bookCount = new AtomicInteger(); AtomicInteger sentenceCount = new AtomicInteger(); try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(fileName))))) { AtomicInteger i = new AtomicInteger(); scores.entrySet().forEach(score -> { writeLine(writer,//from w ww . j av a 2s . c o m "score_(" + i.incrementAndGet() + "/" + scores.size() + ")" + "" + score.getKey()); Map<String, List<String>> books = score.getValue(); AtomicInteger j = new AtomicInteger(); books.entrySet().forEach(book -> { writeLine(writer, "\tbook_(" + j.incrementAndGet() + "/" + books.size() + ")" + "" + book.getKey()); bookCount.incrementAndGet(); AtomicInteger k = new AtomicInteger(); book.getValue().forEach(sentence -> { writeLine(writer, "\t\tsentence_(" + k.incrementAndGet() + "/" + book.getValue().size() + ")" + "" + sentence); sentenceCount.incrementAndGet(); }); }); }); writeLine(writer, "??" + sentenceCount.get()); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } LOGGER.debug("" + scores.keySet().size()); LOGGER.debug("??" + sentenceCount.get()); LOGGER.debug("?"); }
From source file:net.triptech.metahive.KeyValueIdentifier.java
/** * Calculate the key value by concatenating the values. * * @param values the values/* ww w .ja va 2s. c om*/ * @return the object */ public static Object concat(final List<Object> values) { Object keyValue = null; TreeMap<String, Integer> valueSet = new TreeMap<String, Integer>(); for (Object value : values) { if (value instanceof String) { valueSet.put((String) value, 0); } } if (valueSet.size() > 0) { StringBuilder sb = new StringBuilder(); int count = valueSet.keySet().size(); int counter = 1; for (String item : valueSet.keySet()) { if (sb.length() > 0) { if (counter == count) { sb.append(" and "); } else { sb.append(", "); } } sb.append(item); counter++; } keyValue = sb.toString(); } return keyValue; }