List of usage examples for java.util TreeMap put
public V put(K key, V value)
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.//from w w w .ja v a 2 s.c o m * * 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:com.opengamma.analytics.financial.provider.calculator.discounting.CashFlowEquivalentCalculator.java
/** * Add a cash flow amount at a given time in the flow map. If the time is present, the amount is added; if the time is not present a new entry is created. * @param flow The map describing the cash flows. * @param time The time of the flow to add. * @param amount The amount of the flow to add. *//*from w w w .j a v a 2s . c om*/ private static void addcf(final TreeMap<Double, Double> flow, final double time, final double amount) { if (flow.containsKey(time)) { flow.put(time, flow.get(time) + amount); } else { flow.put(time, amount); } }
From source file:Main.java
private static void MyPut(TreeMap<String, String> map, String key, String value) { for (Entry<String, String> entry : map.entrySet()) { String keyOld = entry.getKey(); String valueOld = entry.getValue(); if (keyOld.equals(key)) { value = valueOld + "&" + value; break; }/*www. java2s.com*/ } map.put(key, value); }
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); }/*ww w. j av a2 s . c om*/ return result; }
From source file:ec.nbdemetra.ui.demo.ComponentsDemo.java
private static SortedMap<Id, Component> lookupComponents() { TreeMap<Id, Component> result = Maps.newTreeMap(); for (DemoComponentFactory o : Lookup.getDefault().lookupAll(DemoComponentFactory.class)) { for (Entry<Id, Callable<Component>> e : o.getComponents().entrySet()) { result.put(e.getKey(), configure(create(e.getValue()))); }/*from w ww . j a v a 2 s. c om*/ } return result; }
From source file:com.huawei.streaming.cql.LocalTaskCommons.java
/** * ??/*from w ww . j a v a 2 s. c o m*/ * @return ? */ public static TreeMap<String, String> createLocalConfs() { TreeMap<String, String> config = Maps.newTreeMap(); config.put("streaming.storm.submit.islocal", "true"); // config.put("streaming.storm.submit.islocal", "false"); // config.put("streaming.storm.nimbus.host", "160.133.0.107"); return config; }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step9AgreementCollector.java
public static TreeMap<Integer, SortedMap<String, String>> collectSentenceIDs(JCas jCas) { // for each sentence, we'll collect all its annotations TreeMap<Integer, SortedMap<String, String>> result = new TreeMap<>(); for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) { int sentenceID = sentence.getBegin(); // sentence begin is its ID result.put(sentenceID, new TreeMap<>()); }//from w w w .j a va 2 s . c o m return result; }
From source file:com.uber.hoodie.hadoop.realtime.AbstractRealtimeRecordReader.java
/** * Given a comma separated list of field names and positions at which they appear on Hive, return * a ordered list of field names, that can be passed onto storage. *//*from w ww .ja v a2 s . com*/ public static List<String> orderFields(String fieldNameCsv, String fieldOrderCsv, String partitioningFieldsCsv) { String[] fieldOrders = fieldOrderCsv.split(","); Set<String> partitioningFields = Arrays.stream(partitioningFieldsCsv.split(",")) .collect(Collectors.toSet()); List<String> fieldNames = Arrays.stream(fieldNameCsv.split(",")) .filter(fn -> !partitioningFields.contains(fn)).collect(Collectors.toList()); // Hive does not provide ids for partitioning fields, so check for lengths excluding that. if (fieldNames.size() != fieldOrders.length) { throw new HoodieException( String.format("Error ordering fields for storage read. #fieldNames: %d, #fieldPositions: %d", fieldNames.size(), fieldOrders.length)); } TreeMap<Integer, String> orderedFieldMap = new TreeMap<>(); for (int ox = 0; ox < fieldOrders.length; ox++) { orderedFieldMap.put(Integer.parseInt(fieldOrders[ox]), fieldNames.get(ox)); } return new ArrayList<>(orderedFieldMap.values()); }
From source file:com.zoterodroid.client.ZoteroApi.java
/** * Fetches users bookmarks//from w w w . j a v a 2 s . co m * * @param account The account being synced. * @param authtoken The authtoken stored in the AccountManager for the * account * @return list The list of bookmarks received from the server. * @throws AuthenticationException */ public static ArrayList<Citation> getChangedBookmarks(Account account, Context context) throws IOException, AuthenticationException { ArrayList<Citation> bookmarkList = new ArrayList<Citation>(); String response = null; TreeMap<String, String> params = new TreeMap<String, String>(); String url = FETCH_CHANGED_BOOKMARKS_URI; params.put("hashes", "yes"); response = ZoteroApiCall(url, params, account, context); if (response.contains("<?xml")) { bookmarkList = Citation.valueOf(response); } else { Log.e(TAG, "Server error in fetching bookmark list"); throw new IOException(); } return bookmarkList; }
From source file:cht.Parser.java
@SuppressWarnings("unchecked") static TreeMap<String, Object> myPut(TreeMap<String, Object> parentMap, String rootName, String leftName) { //int firstdot = key.indexOf("."); Object old = null;/*from www. j ava2 s . c o m*/ if (leftName == null || leftName.length() == 0) { // is Leaf // is string only parentMap.put(rootName, value); return parentMap; } else { TreeMap<String, Object> childMap = null; if (parentMap.get(rootName) != null) { old = parentMap.get(rootName); if (old instanceof TreeMap == false) { System.out.println("different type of key:" + rootName); return parentMap; } childMap = (TreeMap<String, Object>) old; } else { childMap = new TreeMap<String, Object>(); } int firstdot = leftName.indexOf("."); String keyName, keyAttribute; if (firstdot > 0) {// c, d.f --> d, f keyName = leftName.substring(0, firstdot); keyAttribute = leftName.substring(firstdot + 1); } else {// c, d -> d, null keyName = leftName; keyAttribute = null; } TreeMap<String, Object> object = myPut(childMap, keyName, keyAttribute); parentMap.put(rootName, object); return parentMap; } }