List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:org.cloudata.core.client.TabletLocationCache.java
protected TabletInfo findFromCache(String tableName, TreeMap<Row.Key, TabletInfo> cache, Row.Key cacheRowKey, Row.Key dataRowKey) {/*from w w w . j a va 2s. co m*/ cacheLock.obtainReadLock(); try { if (cache.containsKey(cacheRowKey)) { TabletInfo tabletInfo = cache.get(cacheRowKey); if (tabletInfo.belongRowRange(cacheRowKey)) { return tabletInfo; } else { return null; } } SortedMap<Row.Key, TabletInfo> tailMap = cache.tailMap(cacheRowKey); if (tailMap.isEmpty()) { return null; } Row.Key tailFirst = tailMap.firstKey(); TabletInfo tabletInfo = tailMap.get(tailFirst); if (tableName.equals(tabletInfo.getTableName()) && tabletInfo.belongRowRange(dataRowKey)) { return tabletInfo; } else { return null; } } finally { cacheLock.releaseReadLock(); } }
From source file:com.sfs.whichdoctor.importer.Importer.java
/** * Process data.//from w w w. j a v a 2 s . c o m * * @param type the type * @param data the data * @param columns the columns * @param applicationContext the application context * * @throws IOException Signals that an I/O exception has occurred. */ public final void processData(final String type, final TreeMap<Integer, TreeMap<Integer, String>> data, final TreeMap<Integer, String> columns, final ApplicationContext applicationContext) throws IOException { HashMap<String, List<String>> dataMap = new HashMap<String, List<String>>(); if (data != null && columns != null) { // Iterate through the columns assigning values to the dataMap for (Integer columnNumber : columns.keySet()) { String columnField = columns.get(columnNumber); if (StringUtils.isNotBlank(columnField)) { // The column has been associated to some data ArrayList<String> dataValues = new ArrayList<String>(); for (Integer rowNumber : data.keySet()) { TreeMap<Integer, String> rowData = data.get(rowNumber); if (rowData.containsKey(columnNumber)) { // Get the value of the column and add it array String dataField = rowData.get(columnNumber); dataValues.add(dataField); } } // Add the data name and array to the dataMap dataMap.put(columnField, dataValues); } } // Store the completed dataMap setDataMap(dataMap); } // Take the dataMap and load the relevant objects into the bean map if (StringUtils.equalsIgnoreCase(type, "exam")) { importLogger.debug("Processing exam import"); try { ExamImporter examImporter = new ExamImporter(); examImporter.setDataMap(getDataMap()); /* Process the data map and turn it into a bean map */ final PersonDAO personDAO = (PersonDAO) applicationContext.getBean("personDAO"); setBeanMap(examImporter.assignData(personDAO)); setDescriptionMap(examImporter.getDescriptionMap()); setImportMessage(examImporter.getImportMessage()); } catch (Exception e) { importLogger.error("Error processing exam import: " + e.getMessage()); throw new IOException("Error processing exam import: " + e.getMessage()); } } }
From source file:org.apache.camel.dataformat.bindy.BindyFixedLengthFactory.java
public String unbind(Map<String, Object> model) throws Exception { StringBuilder buffer = new StringBuilder(); results = new HashMap<Integer, List>(); for (Class clazz : models) { if (model.containsKey(clazz.getName())) { Object obj = model.get(clazz.getName()); if (LOG.isDebugEnabled()) { LOG.debug("Model object: " + obj + ", class: " + obj.getClass().getName()); }// w ww . jav a 2 s . co m if (obj != null) { // Generate Fixed Length table // containing the positions of the fields generateFixedLengthPositionMap(clazz, obj); } } } // Convert Map<Integer, List> into List<List> TreeMap<Integer, List> sortValues = new TreeMap<Integer, List>(results); for (Integer key : sortValues.keySet()) { // Get list of values List<String> val = sortValues.get(key); String value = val.get(0); buffer.append(value); } return buffer.toString(); }
From source file:mrmc.chart.ROCCurvePlot.java
/** * Converts the mapping of readers to curve points into a collection of * separate XY data./* ww w . j a v a 2 s .c om*/ * * @param treeMap Mapping of readers to points defining a curve */ private void createDataset(TreeMap<String, TreeSet<XYPair>> treeMap) { seriesCollection = new XYSeriesCollection(); readerSeriesTitles = new ArrayList<String>(); for (String r : treeMap.keySet()) { XYSeries series = new XYSeries("" + r, false); readerSeriesTitles.add("" + r); for (XYPair point : treeMap.get(r)) { series.add(point.x, point.y); } seriesCollection.addSeries(series); } allLines = new ArrayList<InterpolatedLine>(); for (String r : treeMap.keySet()) { allLines.add(new InterpolatedLine(treeMap.get(r))); } XYSeries vertAvg = generateVerticalROC(); seriesCollection.addSeries(vertAvg); XYSeries horizAvg = generateHorizontalROC(); seriesCollection.addSeries(horizAvg); XYSeries diagAvg = generateDiagonalROC(treeMap); seriesCollection.addSeries(diagAvg); XYSeries pooledAvg = new XYSeries("Pooled Average", false); seriesCollection.addSeries(pooledAvg); }
From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java
private static TreeMap readVomsesFile(File file) { TreeMap vosInfo = new TreeMap<String, List>(); BufferedReader br;/*www. ja v a 2s . c om*/ try { br = new BufferedReader(new FileReader(file)); String line; //int counter=0; while ((line = br.readLine()) != null) { if (!line.trim().equals("")) { String[] info = line.split("\" \""); TreeMap temp = null; String voname = ""; for (int i = 0; i < info.length; i++) { if (i == 0) { temp = new TreeMap<String, String>(); voname = info[i].substring(1); } else if (i == 4) { temp.put("servervoname", info[i].substring(0, info[i].length() - 1)); //Find if the same voname already exists if (vosInfo.containsKey(voname)) { List multiValue = (List) vosInfo.get(voname); multiValue.add(temp); vosInfo.put(voname, multiValue); } else { List singleValue = new ArrayList(); singleValue.add(temp); vosInfo.put(voname, singleValue); } } else { if (i == 1) { temp.put("server", info[i]); } else if (i == 2) { temp.put("port", info[i]); } else if (i == 3) { temp.put("dn", info[i]); } } } //counter++; } } br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return vosInfo; }
From source file:com.sfs.whichdoctor.analysis.GroupAnalysisDAOImpl.java
/** * Analyse a set of groups.//from w ww . j a v a 2 s . c o m * * @param groups the groups * @param loadDetails the load details * @param user the user * * @return the group analysis bean * * @throws WhichDoctorAnalysisDaoException the which doctor analysis dao * exception */ public final GroupAnalysisBean analyse(final Collection<Integer> groups, final BuilderBean loadDetails, final UserBean user) throws WhichDoctorAnalysisDaoException { GroupAnalysisBean groupAnalysis = new GroupAnalysisBean(); Collection<Object> variables = new ArrayList<Object>(); for (Integer groupGUID : groups) { dataLogger.debug("Analyising Group GUID: " + groupGUID); variables.add(groupGUID); } dataLogger.debug("Group variables size: " + variables.size()); if (variables.size() == 0) { dataLogger.error("Cannot perform group analysis with no groups"); throw new WhichDoctorAnalysisDaoException("Cannot perform group analysis with no groups"); } SearchBean search = this.searchDAO.initiate("group", user); search.setSearchArray(variables, "Group GUIDs"); search.setLimit(0); try { BuilderBean groupDetails = new BuilderBean(); groupDetails.setParameter("ITEMS", true); SearchResultsBean results = this.searchDAO.search(search, groupDetails); Collection<Object> searchResults = results.getSearchResults(); if (searchResults != null) { for (Object group : searchResults) { groupAnalysis.addGroup((GroupBean) group); } } } catch (Exception e) { dataLogger.error("Error performing Group Analysis search: " + e.getMessage()); } /* Iterate through each group's itembeans, adding them to the item map */ for (Integer groupGUID : groupAnalysis.getGroups().keySet()) { GroupBean group = groupAnalysis.getGroups().get(groupGUID); TreeMap<String, ItemBean> items = group.getItems(); if (items != null) { for (String key : items.keySet()) { ItemBean item = items.get(key); groupAnalysis.addReferenceGUID(item.getObject2GUID(), group.getGUID()); } } } /* * Build the CombinedGroup map using the groupGUID and referenceGUID * maps */ for (Integer referenceGUID : groupAnalysis.getReferenceGUIDs().keySet()) { ArrayList<Integer> groupGUIDs = groupAnalysis.getReferenceGUIDs().get(referenceGUID); groupAnalysis.addCombinedGroup(referenceGUID, groupGUIDs); } /* * With the referenceGUIDs/groupGUIDs organised load the referenceGUID * objects */ try { groupAnalysis.setReferenceObjects(loadReferenceObjects(groupAnalysis.getReferenceGUIDs(), loadDetails, user, groupAnalysis.getGroupClass())); } catch (Exception e) { dataLogger.error("Error loading reference objects: " + e.getMessage()); } /* With the objects loaded build the order map */ groupAnalysis .setReferenceOrder(buildOrder(groupAnalysis.getReferenceObjects(), groupAnalysis.getGroupClass())); return groupAnalysis; }
From source file:org.apache.sysml.runtime.compress.PlanningBinPacker.java
private TreeMap<Float, List<List<Integer>>> packFirstFit(List<Integer> items, List<Float> itemWeights) { // when searching for a bin, the first bin in the list is used TreeMap<Float, List<List<Integer>>> bins = new TreeMap<Float, List<List<Integer>>>(); // first bin//from w ww . j a va 2s .c o m bins.put(_binWeight, createBinList()); int numItems = items.size(); for (int i = 0; i < numItems; i++) { float itemWeight = itemWeights.get(i); Map.Entry<Float, List<List<Integer>>> entry = bins.ceilingEntry(itemWeight); if (entry == null) { // new bin float newBinWeight = _binWeight - itemWeight; List<List<Integer>> binList = bins.get(newBinWeight); if (binList == null) { bins.put(newBinWeight, createBinList(items.get(i))); } else { List<Integer> newBin = new ArrayList<Integer>(); newBin.add(items.get(i)); binList.add(newBin); } } else { // add to the first bin in the list List<Integer> assignedBin = entry.getValue().remove(0); assignedBin.add(items.get(i)); if (entry.getValue().size() == 0) bins.remove(entry.getKey()); float newBinWeight = entry.getKey() - itemWeight; List<List<Integer>> newBinsList = bins.get(newBinWeight); if (newBinsList == null) { // new bin bins.put(newBinWeight, createBinList(assignedBin)); } else { newBinsList.add(assignedBin); } } } return bins; }
From source file:gsn.wrappers.general.CSVHandler.java
public ArrayList<TreeMap<String, Serializable>> parseValues(Reader datainput, long previousCheckPoint) throws IOException { ArrayList<TreeMap<String, Serializable>> toReturn = new ArrayList<TreeMap<String, Serializable>>(); CSVReader reader = new CSVReader(datainput, getSeparator(), getStringSeparator(), getSkipFirstXLines()); String[] values = null;//from ww w. j ava 2s . c o m long currentLine = 0; while ((values = reader.readNext()) != null) { TreeMap<String, Serializable> se = convertTo(formats, fields, getNulls(), values, getSeparator()); if (isEmpty(se)) continue; if (se.containsKey(TIMESTAMP)) { //System.out.println("times "+se.get(TIMESTAMP)+"--"+previousCheckPoint); if (((Long) se.get(TIMESTAMP)) <= previousCheckPoint) continue; } else {// assuming useCounterForCheckPoint = true if (logger.isDebugEnabled()) { String symbol = (currentLine < previousCheckPoint) ? " < " : " >= "; logger.debug("currentLine=" + currentLine + symbol + "checkpoint=" + previousCheckPoint); } if (currentLine < previousCheckPoint) {// skipping already read lines, based on line count logger.debug("skipping"); currentLine++; continue; } } toReturn.add(se); currentLine++; loggedNoChange = false; if (toReturn.size() > 250) break; // Move outside the loop as in each call we only read 250 values; } if (logger.isDebugEnabled() && toReturn.size() == 0 && loggedNoChange == false) { logger.debug("There is no new item after most recent checkpoint(previousCheckPoint:" + new DateTime(previousCheckPoint) + ")."); loggedNoChange = true; } reader.close(); return toReturn; }
From source file:com.masse.mvn.plugin.BuildJsonFromPropertiesMojo.java
private PropertiesToJson createMap(TreeMap<String, PropertiesToJson> json, String key, String value, int level) { String[] ks = key.split("="); String newKey = ""; String jsonKey = ""; PropertiesToJson ptj = null;/*w w w . jav a 2s. c om*/ for (int i = 0; i < level; i++) { newKey += ks[i] + "."; jsonKey = ks[i]; } newKey = newKey.substring(0, newKey.length() - 1); if (json != null) ptj = json.get(newKey); if (ptj == null) { ptj = new PropertiesToJson(); ptj.setKey(newKey); ptj.setJsonKey(jsonKey); } if (level == ks.length) { ptj.setValue(value); } else { String nextKey = getNextKey(newKey, level + 1); PropertiesToJson pj = null; if (json != null) pj = json.get(nextKey); PropertiesToJson p = null; if (pj != null) p = createMap(pj.getChildren(), key, value, level + 1); else p = createMap(null, key, value, level + 1); ptj.getChildren().put(p.getKey(), p); } return ptj; }
From source file:com.wattzap.view.graphs.DistributionGraph.java
public void updateValues(int scale, boolean keepZeroes) { da.setBucketSize(scale);/*w ww .ja v a2s . co m*/ da.setKeepZeroes(keepZeroes); long totalTime = 0; TreeMap<Integer, Long> data = new TreeMap<Integer, Long>(); for (int i = 0; i < telemetry.length; i++) { Telemetry last = null; for (Telemetry t : telemetry[i]) { if (last == null) { // first time through last = t; } else { int key = da.getKey(t); if (key != -1) { if (data.containsKey(key)) { // add time to current key long time = data.get(key); data.put(key, time + (t.getTime() - last.getTime())); } else { data.put(key, t.getTime() - last.getTime()); } totalTime += t.getTime() - last.getTime(); } last = t; } } // for } // for DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Entry<Integer, Long> entry : data.entrySet()) { int key = entry.getKey(); double p = ((double) entry.getValue() * 100 / totalTime); if (p > 0.5) { dataset.addValue(p, "", da.getValueLabel(key)); } } // for plot.setDataset(dataset); chartPanel.revalidate(); }