List of usage examples for java.util TreeMap TreeMap
public TreeMap()
From source file:Main.java
public static Map<String, String> getConfigs(InputStream is) throws IOException, SAXException, ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document dt = db.parse(is);//from w w w .j ava 2 s.co m Element element = dt.getDocumentElement(); Map<String, String> config = new TreeMap<String, String>(); NodeList propertyList = element.getElementsByTagName("property"); int length = propertyList.getLength(); for (int i = 0; i < length; i++) { Node property = propertyList.item(i); String key = property.getChildNodes().item(0).getTextContent(); String value = property.getChildNodes().item(1).getTextContent(); config.put(key, value); } return config; }
From source file:com.enonic.cms.core.RequestParameters.java
public RequestParameters() { this.parameters = new TreeMap<String, Param>(); }
From source file:com.nec.sydney.beans.exportroot.NSBeanUtil.java
public static void setProperties(Object bean, String[] valueArray) throws Exception { if (bean == null || valueArray == null || valueArray.length == 0) { return;/*from w ww. ja v a 2 s . c o m*/ } Map map = new TreeMap(); for (int i = 0; i < valueArray.length; i++) { String keyAndValue = valueArray[i]; if (keyAndValue == null || keyAndValue.indexOf(KEY_VALUE_SPLITER) == -1) { continue; } else { String[] tmpArray = valueArray[i].split(KEY_VALUE_SPLITER, 2); String key = tmpArray[0].trim(); String value = tmpArray[1]; map.put(key, value); } } if (map.size() > 0) { BeanUtils.populate(bean, map); } return; }
From source file:org.starfishrespect.myconsumption.server.business.entities.SensorDataset.java
public SensorDataset(Date timestamp) { this.timestamp = timestamp; values = new TreeMap<Integer, MinuteValues>(); }
From source file:Util.java
/** * Returns an array of indices indicating the order the data should be sorted * in. Duplicate values are discarded with the first one being kept. This method * is useful when a number of data arrays have to be sorted based on the values in * some coordinate array, such as time.// w w w . j a va2 s. com * * To convert a array of values to a sorted monooic array try: <br> * double[] x; // some 1-D array of data <br> * int[] i = MathUtilities.uniqueSort(x); <br> * double[] xSorted = MathUtilities.orderVector(x, i);<br><br> * * @param x An array of data that is to be sorted. * @return order An array of indexes such that y = Array.sort(x) and * y = x(order) are the same. */ public static final synchronized int[] uniqueSort(double[] x) { TreeMap tm = new TreeMap(); for (int i = 0; i < x.length; i++) { Double key = new Double(x[i]); boolean exists = tm.containsKey(key); if (exists) { // Do nothing. Ignore duplicate keys } else { tm.put(key, new Integer(i)); } } Object[] values = tm.values().toArray(); int[] order = new int[values.length]; for (int i = 0; i < values.length; i++) { Integer tmp = (Integer) values[i]; order[i] = tmp.intValue(); } return order; }
From source file:annis.CSVHelper.java
public static SortedMap<Integer, SortedSet<String>> exportCSVHeader(Iterator<AnnotatedMatch> matches, PrintWriter w) {/*from w w w .ja v a 2s. com*/ // figure out what annotations are used at each match position SortedMap<Integer, SortedSet<String>> columnsByNodePos = new TreeMap<>(); while (matches.hasNext()) { AnnotatedMatch match = matches.next(); for (int j = 0; j < match.size(); ++j) { AnnotatedSpan span = match.get(j); if (columnsByNodePos.get(j) == null) { columnsByNodePos.put(j, new TreeSet<String>()); } for (Annotation annotation : span.getAnnotations()) { columnsByNodePos.get(j).add("anno_" + annotation.getQualifiedName()); } for (Annotation meta : span.getMetadata()) { columnsByNodePos.get(j).add("meta_" + meta.getQualifiedName()); } } } CSVWriter csvWriter = new CSVWriter(w, '\t', CSVWriter.NO_QUOTE_CHARACTER, '\\'); // print column names and data types int count = columnsByNodePos.keySet().size(); ArrayList<String> headerLine = new ArrayList<>(); for (int j = 0; j < count; ++j) { headerLine.add(fullColumnName(j + 1, "id")); headerLine.add(fullColumnName(j + 1, "span")); SortedSet<String> annotationNames = columnsByNodePos.get(j); for (String name : annotationNames) { headerLine.add(fullColumnName(j + 1, name)); } } csvWriter.writeNext(headerLine.toArray(new String[headerLine.size()])); return columnsByNodePos; }
From source file:com.jaredrummler.android.devices.DevicesToJson.java
private static List<Manufacturer> getManufacturers(List<Device> devices) { List<Manufacturer> manufacturers = new ArrayList<>(); Map<String, List<Device>> map = new TreeMap<>(); for (Device device : devices) { if (device.manufacturer == null || device.manufacturer.trim().length() == 0) { continue; }/*from w ww.ja v a 2s .co m*/ List<Device> deviceList = map.get(device.manufacturer); if (deviceList == null) { deviceList = new ArrayList<>(); } deviceList.add(new Device(null, device.marketName, device.codename, device.model)); map.put(device.manufacturer, deviceList); } for (Map.Entry<String, List<Device>> entry : map.entrySet()) { manufacturers.add(new Manufacturer(entry.getKey(), entry.getValue())); } return manufacturers; }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step12GolDataExporter.java
public static TreeMap<Integer, Sentence> collectSentenceIDs(JCas jCas) { // for each sentence, we'll collect all its annotations TreeMap<Integer, Sentence> result = new TreeMap<>(); for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) { int sentenceID = sentence.getBegin(); // sentence begin is its ID result.put(sentenceID, sentence); }// w w w . jav a2 s . co m return result; }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java
/** * (1) Plain text with 4 columns: (1) the rank of the document in the list * (2) average agreement rate over queries (3) standard deviation of * agreement rate over queries. (4) average length of the document in the * rank./*from ww w . jav a 2s. com*/ */ public static void statistics1(File inputDir, File outputDir) throws Exception { SortedMap<Integer, DescriptiveStatistics> mapDocumentRankObservedAgreement = new TreeMap<>(); SortedMap<Integer, DescriptiveStatistics> mapDocumentRankDocLength = new TreeMap<>(); // iterate over query containers for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) { QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(f, "utf-8")); for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) { // add new entries if (!mapDocumentRankObservedAgreement.containsKey(rankedResult.rank)) { mapDocumentRankObservedAgreement.put(rankedResult.rank, new DescriptiveStatistics()); } if (!mapDocumentRankDocLength.containsKey(rankedResult.rank)) { mapDocumentRankDocLength.put(rankedResult.rank, new DescriptiveStatistics()); } Double observedAgreement = rankedResult.observedAgreement; if (observedAgreement == null) { System.err .println("Observed agreement is null; " + f.getName() + ", " + rankedResult.clueWebID); } else { // update value mapDocumentRankObservedAgreement.get(rankedResult.rank).addValue(observedAgreement); mapDocumentRankDocLength.get(rankedResult.rank).addValue(rankedResult.plainText.length()); } } } PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats1.csv"))); for (Map.Entry<Integer, DescriptiveStatistics> entry : mapDocumentRankObservedAgreement.entrySet()) { pw.printf(Locale.ENGLISH, "%d\t%.4f\t%.4f\t%.4f\t%.4f%n", entry.getKey(), entry.getValue().getMean(), entry.getValue().getStandardDeviation(), mapDocumentRankDocLength.get(entry.getKey()).getMean(), mapDocumentRankDocLength.get(entry.getKey()).getStandardDeviation()); } pw.close(); }
From source file:com.opengamma.financial.analytics.cashflow.FixedPaymentMatrix.java
public FixedPaymentMatrix() { _values = new TreeMap<LocalDate, MultipleCurrencyAmount>(); _maxCurrencyAmounts = 0; }