List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:net.tsquery.DataEndpoint.java
@SuppressWarnings("unchecked") private JSONObject PlotToDygraphJSON(Plot plot, long tsFrom, long tsTo, int topN) { final JSONObject plotObject = new JSONObject(); final JSONArray nameArray = new JSONArray(); final JSONArray dataArray = new JSONArray(); final int dpCount = plot.getDataPointsSize(); final TreeMap<Long, double[]> tsMap = new TreeMap<>(); final double[] weight = new double[dpCount]; int dpIndex = 0; for (DataPoints dataPoints : plot.getDataPoints()) { for (DataPoint point : dataPoints) { long timestamp = point.timestamp(); if (timestamp < tsFrom || timestamp > tsTo) continue; long tsMSec = timestamp * 1000; if (!tsMap.containsKey(tsMSec)) { double[] values = new double[dpCount]; values[dpIndex] = getValue(point); tsMap.put(tsMSec, values); weight[dpIndex] += ((values[dpIndex]) / 1000000.0); } else { //noinspection MismatchedReadAndWriteOfArray double[] values = tsMap.get(tsMSec); values[dpIndex] = getValue(point); weight[dpIndex] += ((values[dpIndex]) / 1000000.0); }//w ww . ja v a2s . c om } dpIndex++; } HashMap<Integer, Boolean> includeMap = null; // are we performing a topN lookup? if (topN > 0) { includeMap = new HashMap<>(topN); TreeMap<Double, Integer> weightMap = new TreeMap<>(Collections.reverseOrder()); for (int i = 0; i < dpCount; i++) { while (weightMap.containsKey(weight[i])) weight[i] -= 0.00000001; weightMap.put(weight[i], i); } int series = 0; for (Map.Entry<Double, Integer> entry : weightMap.entrySet()) { includeMap.put(entry.getValue(), true); ++series; if (series >= topN) break; } } for (Map.Entry<Long, double[]> entry : tsMap.entrySet()) { JSONArray entryArray = new JSONArray(); entryArray.add(entry.getKey()); final double[] points = entry.getValue(); for (dpIndex = 0; dpIndex < dpCount; dpIndex++) { if ((topN <= 0) || (topN > 0 && includeMap.containsKey(dpIndex))) { entryArray.add(points[dpIndex]); } } dataArray.add(entryArray); } // First column is always the Date nameArray.add("Date"); int index = -1; for (DataPoints dataPoints : plot.getDataPoints()) { index++; // if we are in a topN query and the current index is not included, skip this iteration if (topN > 0 && !includeMap.containsKey(index)) continue; StringBuilder nameBuilder = new StringBuilder(); nameBuilder.append(dataPoints.metricName()).append(":"); Map<String, String> tags = dataPoints.getTags(); for (String s : tags.keySet()) { nameBuilder.append(String.format(" %s=%s", s, tags.get(s))); } nameArray.add(nameBuilder.toString()); } plotObject.put("labels", nameArray); plotObject.put("values", dataArray); return plotObject; }
From source file:edu.isi.wings.portal.controllers.PlanController.java
private ArrayList<ArrayList<TreeMap<String, Binding>>> getDataBindings(VariableBindingsListSet bindingsets) { ArrayList<ArrayList<TreeMap<String, Binding>>> blistsets = new ArrayList<ArrayList<TreeMap<String, Binding>>>(); for (ArrayList<VariableBindingsList> bindings : bindingsets) { HashMap<String, Boolean> bindingstrs = new HashMap<String, Boolean>(); ArrayList<TreeMap<String, Binding>> blist = new ArrayList<TreeMap<String, Binding>>(); for (VariableBindingsList binding : bindings) { TreeMap<String, Binding> xbindings = new TreeMap<String, Binding>(); for (VariableBindings vb : binding) { String vname = vb.getDataVariable().getName(); Binding b = new Binding(); for (KBObject obj : vb.getDataObjects()) { Binding cb = new Binding(obj.getID()); if (vb.getDataObjects().size() == 1) b = cb;/*ww w .java 2 s . com*/ else b.add(cb); } xbindings.put(vname, b); } String bstr = ""; for (String v : xbindings.keySet()) { bstr += xbindings.get(v).toString() + ","; } if (!bindingstrs.containsKey(bstr)) { bindingstrs.put(bstr, true); blist.add(xbindings); } } blistsets.add(blist); } return blistsets; }
From source file:com.espertech.esper.rowregex.EventRowRegexNFAView.java
private List<RegexNFAStateEntry> rankEndStatesWithinPartitionByStart(List<RegexNFAStateEntry> endStates) { if (endStates.isEmpty()) { return endStates; }//from w ww . j a v a 2 s . com if (endStates.size() == 1) { return endStates; } TreeMap<Integer, Object> endStatesPerBeginEvent = new TreeMap<Integer, Object>(); for (RegexNFAStateEntry entry : endStates) { Integer endNum = entry.getMatchBeginEventSeqNo(); Object value = endStatesPerBeginEvent.get(endNum); if (value == null) { endStatesPerBeginEvent.put(endNum, entry); } else if (value instanceof List) { List<RegexNFAStateEntry> entries = (List<RegexNFAStateEntry>) value; entries.add(entry); } else { List<RegexNFAStateEntry> entries = new ArrayList<RegexNFAStateEntry>(); entries.add((RegexNFAStateEntry) value); entries.add(entry); endStatesPerBeginEvent.put(endNum, entries); } } if (endStatesPerBeginEvent.size() == 1) { List<RegexNFAStateEntry> endStatesUnranked = (List<RegexNFAStateEntry>) endStatesPerBeginEvent.values() .iterator().next(); if (matchRecognizeSpec.isAllMatches()) { return endStatesUnranked; } RegexNFAStateEntry chosen = rankEndStates(endStatesUnranked); return Collections.singletonList(chosen); } List<RegexNFAStateEntry> endStatesRanked = new ArrayList<RegexNFAStateEntry>(); Set<Integer> keyset = endStatesPerBeginEvent.keySet(); Integer[] keys = keyset.toArray(new Integer[keyset.size()]); for (Integer key : keys) { Object value = endStatesPerBeginEvent.remove(key); if (value == null) { continue; } RegexNFAStateEntry entryTaken; if (value instanceof List) { List<RegexNFAStateEntry> endStatesUnranked = (List<RegexNFAStateEntry>) value; if (endStatesUnranked.isEmpty()) { continue; } entryTaken = rankEndStates(endStatesUnranked); if (matchRecognizeSpec.isAllMatches()) { endStatesRanked.addAll(endStatesUnranked); // we take all matches and don't rank except to determine skip-past } else { endStatesRanked.add(entryTaken); } } else { entryTaken = (RegexNFAStateEntry) value; endStatesRanked.add(entryTaken); } // could be null as removals take place if (entryTaken != null) { if (matchRecognizeSpec.getSkip().getSkip() == MatchRecognizeSkipEnum.PAST_LAST_ROW) { int skipPastRow = entryTaken.getMatchEndEventSeqNo(); removeSkippedEndStates(endStatesPerBeginEvent, skipPastRow); } else if (matchRecognizeSpec.getSkip().getSkip() == MatchRecognizeSkipEnum.TO_NEXT_ROW) { int skipPastRow = entryTaken.getMatchBeginEventSeqNo(); removeSkippedEndStates(endStatesPerBeginEvent, skipPastRow); } } } return endStatesRanked; }
From source file:org.apache.nutch.crawl.CrawlDbReader.java
public Object query(Map<String, String> args, Configuration conf, String type, String crawlId) throws Exception { Map<String, Object> results = new HashMap<>(); String crawlDb = crawlId + "/crawldb"; if (type.equalsIgnoreCase("stats")) { boolean sort = false; if (args.containsKey("sort")) { if (args.get("sort").equalsIgnoreCase("true")) sort = true;//from w w w. j a v a2 s . c om } TreeMap<String, Writable> stats = processStatJobHelper(crawlDb, NutchConfiguration.create(), sort); LongWritable totalCnt = (LongWritable) stats.get("T"); stats.remove("T"); results.put("totalUrls", String.valueOf(totalCnt.get())); Map<String, Object> statusMap = new HashMap<>(); for (Map.Entry<String, Writable> entry : stats.entrySet()) { String k = entry.getKey(); long val = 0L; double fval = 0.0; if (entry.getValue() instanceof LongWritable) { val = ((LongWritable) entry.getValue()).get(); } else if (entry.getValue() instanceof FloatWritable) { fval = ((FloatWritable) entry.getValue()).get(); } else if (entry.getValue() instanceof BytesWritable) { continue; } if (k.equals("scn")) { results.put("minScore", String.valueOf(fval)); } else if (k.equals("scx")) { results.put("maxScore", String.valueOf(fval)); } else if (k.equals("sct")) { results.put("avgScore", String.valueOf((fval / totalCnt.get()))); } else if (k.startsWith("status")) { String[] st = k.split(" "); int code = Integer.parseInt(st[1]); if (st.length > 2) { @SuppressWarnings("unchecked") Map<String, Object> individualStatusInfo = (Map<String, Object>) statusMap .get(String.valueOf(code)); Map<String, String> hostValues; if (individualStatusInfo.containsKey("hostValues")) { hostValues = (Map<String, String>) individualStatusInfo.get("hostValues"); } else { hostValues = new HashMap<>(); individualStatusInfo.put("hostValues", hostValues); } hostValues.put(st[2], String.valueOf(val)); } else { Map<String, Object> individualStatusInfo = new HashMap<>(); individualStatusInfo.put("statusValue", CrawlDatum.getStatusName((byte) code)); individualStatusInfo.put("count", String.valueOf(val)); statusMap.put(String.valueOf(code), individualStatusInfo); } } else { results.put(k, String.valueOf(val)); } } results.put("status", statusMap); return results; } if (type.equalsIgnoreCase("dump")) { String output = args.get("out_dir"); String format = "normal"; String regex = null; Integer retry = null; String status = null; String expr = null; Float sample = null; if (args.containsKey("format")) { format = args.get("format"); } if (args.containsKey("regex")) { regex = args.get("regex"); } if (args.containsKey("retry")) { retry = Integer.parseInt(args.get("retry")); } if (args.containsKey("status")) { status = args.get("status"); } if (args.containsKey("expr")) { expr = args.get("expr"); } if (args.containsKey("sample")) { sample = Float.parseFloat(args.get("sample")); } processDumpJob(crawlDb, output, conf, format, regex, status, retry, expr, sample); File dumpFile = new File(output + "/part-00000"); return dumpFile; } if (type.equalsIgnoreCase("topN")) { String output = args.get("out_dir"); long topN = Long.parseLong(args.get("nnn")); float min = 0.0f; if (args.containsKey("min")) { min = Float.parseFloat(args.get("min")); } processTopNJob(crawlDb, topN, min, output, conf); File dumpFile = new File(output + "/part-00000"); return dumpFile; } if (type.equalsIgnoreCase("url")) { String url = args.get("url"); CrawlDatum res = get(crawlDb, url, conf); results.put("status", res.getStatus()); results.put("fetchTime", new Date(res.getFetchTime())); results.put("modifiedTime", new Date(res.getModifiedTime())); results.put("retriesSinceFetch", res.getRetriesSinceFetch()); results.put("retryInterval", res.getFetchInterval()); results.put("score", res.getScore()); results.put("signature", StringUtil.toHexString(res.getSignature())); Map<String, String> metadata = new HashMap<>(); if (res.getMetaData() != null) { for (Entry<Writable, Writable> e : res.getMetaData().entrySet()) { metadata.put(String.valueOf(e.getKey()), String.valueOf(e.getValue())); } } results.put("metadata", metadata); return results; } return results; }
From source file:eu.sisob.uma.crawler.AirResearchersWebPagesExtractor.java
/** * In this block the crawler will try to extract the departments web adresses. * The block works with a org.dom4j.Element * Notes://from w w w . j a v a 2s.com * The function iterate the institution elemento taking all the UNIT_OF_ASSESSMENT to search all of them in same crawler call. * The UNIT_OF_ASSESSMENT will be stores in subjects array, next, it will be given to the crawler. * * @param elementInstitution * @param path * @param sInstitutionName * @param sWebAddress * @return */ @Override protected boolean actionsInInstitutionNode(org.dom4j.Element elementInstitution, String path, String sInstitutionName, String sWebAddress) { if (refuseExecution) return false; String crawler_data_folder = this.work_dir.getAbsolutePath() + File.separator + CRAWLER_DATA_FOLDERNAME; List<String> subjects = new ArrayList<String>(); String sSeed = sWebAddress; String sContainPattern = sSeed.replace("http://www.", ""); int index = sContainPattern.indexOf("/"); if (index == -1) index = sContainPattern.length() - 1; sContainPattern = sContainPattern.substring(0, index); ProjectLogger.LOGGER.info("Department phase - " + sInstitutionName); /* * Taking subjects to search its web adresses */ String sUnitOfAssessment_Description = ""; for (Iterator<org.dom4j.Element> i2 = elementInstitution.elementIterator(XMLTags.UNIT_OF_ASSESSMENT); i2 .hasNext();) { sUnitOfAssessment_Description = i2.next().element(XMLTags.UNIT_OF_ASSESSMENT_DESCRIPTION).getText(); subjects.add(sUnitOfAssessment_Description); ProjectLogger.LOGGER.info( "\tAdding subject '" + sUnitOfAssessment_Description + "' to search its section webpages"); } /* * Crawling to search the departments */ CrawlerDepartamentsV3Controller controllerDepts = null; try { String university_crawler_data_folder = crawler_data_folder + File.separator + sInstitutionName.replaceAll("\\W+", "").toLowerCase() + "-crawler-data"; File university_crawler_data_dir = new File(university_crawler_data_folder); if (university_crawler_data_dir.exists()) FileFootils.deleteDir(university_crawler_data_dir); controllerDepts = new CrawlerDepartamentsV3Controller(university_crawler_data_folder, this.keywords_data_dir, subjects); controllerDepts.addSeed(sSeed); controllerDepts.setPolitenessDelay(200); controllerDepts.setMaximumCrawlDepth(3); controllerDepts.setMaximumPagesToFetch(-1); controllerDepts.setContainPattern(sContainPattern); controllerDepts.clearPossibleResults(); ProjectLogger.LOGGER .info("Begin crawling: " + sInstitutionName + " (" + sWebAddress + ") - [" + sSeed + "]"); long lTimerAux = java.lang.System.currentTimeMillis(); controllerDepts.start(CrawlerDepartamentsV3.class, 1); lTimerAux = java.lang.System.currentTimeMillis() - lTimerAux; ProjectLogger.LOGGER .info("End crawling: " + sInstitutionName + " - Time: " + lTimerAux + " ms - [" + sSeed + "]"); } catch (Exception ex) { ProjectLogger.LOGGER.error(ex.getMessage(), ex); } finally { if (CrawlerTrace.isTraceUrlsActive() && controllerDepts != null) controllerDepts.closeCrawlerTrace(); controllerDepts.releaseResources(); } /* * Update results */ if (controllerDepts != null) { if (CrawlerTrace.isTraceSearchActive()) { CandidateTypeURL.printResults("Results of: " + sInstitutionName + " (" + sWebAddress + ") by TYPE", controllerDepts.getPossibleResultsTYPE()); } /* * Adding departments web addresses to xml document */ for (Iterator<org.dom4j.Element> i2 = elementInstitution.elementIterator(XMLTags.UNIT_OF_ASSESSMENT); i2 .hasNext();) { org.dom4j.Element e2 = i2.next(); sUnitOfAssessment_Description = e2.element(XMLTags.UNIT_OF_ASSESSMENT_DESCRIPTION).getText(); TreeMap<String, List<CandidateTypeURL>> t = controllerDepts.getPossibleResultsTYPE(); Iterator<String> it = t.keySet().iterator(); // String department_of = CrawlerDepartamentsV3Controller.DEPARTMENT_OF_RESULT_TAG + sUnitOfAssessment_Description; //FIXME, TEST THIS //while(it.hasNext()) //{ // String department_of = it.next(); // if(department_of.toLowerCase().equals(CrawlerDepartamentsV3Controller.DEPARTMENT_OF_RESULT_TAG + sUnitOfAssessment_Description.toLowerCase())) // { List<CandidateTypeURL> lst = t.get(department_of); if (lst != null) { for (CandidateTypeURL ss : lst) { ProjectLogger.LOGGER .info("Add department '" + department_of + "' the url '" + ss.sURL + "'"); e2.addElement(XMLTags.DEPARTMENT_WEB_ADDRESS).addText(ss.sURL); } } // break; // } //} } } return true; }
From source file:net.unconventionalthinking.hierarchy.langsymboltable.LangSymbolTable_File.java
private Object lookup_Worker(Map symbolTableToSearch, String symbolName) { TreeMap symbol_TreeMap = (TreeMap) symbolTableToSearch.get(symbolName); if (symbol_TreeMap != null) { // search from the top the scope to bottom for the first match Object highestMatching_SymbolOrOverloadedMethodsList = null; LangSymbolScopeStack.ScopeInfo[] currScopeStack = scopeStack.getScopeStack() .toArray(new LangSymbolScopeStack.ScopeInfo[scopeStack.getScopeStack().size()]); for (int i = currScopeStack.length - 1; highestMatching_SymbolOrOverloadedMethodsList == null && i >= 0; --i) { LangSymbolScopeStack.ScopeInfo currScopeInfo = currScopeStack[i]; highestMatching_SymbolOrOverloadedMethodsList = symbol_TreeMap .get(new Integer(currScopeInfo.scope_Id)); }/*from w w w . ja v a 2 s .com*/ return highestMatching_SymbolOrOverloadedMethodsList; } else { return null; } }
From source file:ark.model.SupervisedModelCreg.java
@Override protected AssignmentList toParseInternalHelper(AssignmentList internalAssignments) { TreeMap<Double, List<String>> sortedWeights = new TreeMap<Double, List<String>>(); File modelFile = new File(this.modelPath.getValue()); if (!modelFile.exists()) return internalAssignments; try {/*from w w w. jav a2s . c o m*/ BufferedReader br = new BufferedReader(new FileReader(modelFile)); String line = null; while ((line = br.readLine()) != null) { String[] lineParts = line.split("\t"); Double value = null; if (lineParts.length < 3) continue; try { value = Math.abs(Double.parseDouble(lineParts[2])); } catch (NumberFormatException e) { continue; } if (!sortedWeights.containsKey(value)) sortedWeights.put(value, new ArrayList<String>()); sortedWeights.get(value).add(line); } br.close(); } catch (Exception e) { e.printStackTrace(); } NavigableMap<Double, List<String>> descendingWeights = sortedWeights.descendingMap(); int i = 0; for (List<String> lines : descendingWeights.values()) { for (String line : lines) { internalAssignments .add(Assignment.assignmentTyped(null, Context.ARRAY_STR, "w-" + i, Obj.stringValue(line))); i++; } } return internalAssignments; }
From source file:org.apache.slider.common.tools.SliderUtils.java
/** * Built a (sorted) map of application reports, mapped to the instance name * The list is sorted, and the addition process does not add a report * if there is already one that exists. If the list handed in is sorted, * those that are listed first form the entries returned * @param instances list of intances//from w ww . ja va2s . c o m * @param minState minimum YARN state to be included * @param maxState maximum YARN state to be included * @return all reports in the list whose state >= minimum and <= maximum */ public static Map<String, ApplicationReport> buildApplicationReportMap(List<ApplicationReport> instances, YarnApplicationState minState, YarnApplicationState maxState) { TreeMap<String, ApplicationReport> map = new TreeMap<String, ApplicationReport>(); for (ApplicationReport report : instances) { YarnApplicationState state = report.getYarnApplicationState(); if (state.ordinal() >= minState.ordinal() && state.ordinal() <= maxState.ordinal() && map.get(report.getName()) == null) { map.put(report.getName(), report); } } return map; }
From source file:de.nec.nle.siafu.model.DiscreteOverlay.java
/** * Create a discrete overlay using the thresholds int he configuration * object.//from w w w.ja v a2 s. c o m * * @param name * the name of the overlay * @param is * the InputStream with the image that represents the values * @param simulationConfig * the configuration file where the threshold details are given */ public DiscreteOverlay(final String name, final InputStream is, final Configuration simulationConfig) { super(name, is); // A tree to sort the thresholds TreeMap<Integer, String> intervals = new TreeMap<Integer, String>(); // Find out how many thresholds we have String[] property; try { property = simulationConfig.getStringArray("overlays." + name + ".threshold[@tag]"); if (property.length == 0) throw new ConfigurationRuntimeException(); } catch (ConfigurationRuntimeException e) { throw new RuntimeException("You forgot the description of " + name + " in the config file"); } thresholds = new int[property.length]; tags = new String[property.length]; // Read the thresholds for (int i = 0; i < property.length; i++) { String tag = simulationConfig.getString("overlays." + name + ".threshold(" + i + ")[@tag]"); int pixelValue = simulationConfig.getInt("overlays." + name + ".threshold(" + i + ")[@pixelvalue]"); intervals.put(pixelValue, tag); } // Store the sorted thresholds int i = 0; for (int key : intervals.keySet()) { thresholds[i] = key; tags[i] = intervals.get(key); i++; } }
From source file:com.impetus.ankush2.framework.monitor.AbstractMonitor.java
/** * Method to convert null value maps to list object. * /* w w w. jav a 2s . co m*/ * @param treeMap * the tree map * @return the object */ private static Object convertToList(TreeMap treeMap) { // if treemap is null or empty return null. if (treeMap == null || treeMap.isEmpty()) return null; boolean isList = false; // item set List itemSet = new ArrayList(); // iterating over the treemap. for (Object m : treeMap.keySet()) { // item key. String itemKey = m.toString(); // if value is null. if (treeMap.get(itemKey) == null) { isList = true; // adding item to item set. itemSet.add(itemKey); } else { // getting the object. Object obj = convertToList((TreeMap) (treeMap.get(itemKey))); // empty map. TreeMap map = new TreeMap(); // putting object in map. map.put(itemKey, obj); // putting object in tree map. treeMap.put(itemKey, obj); // adding the item in set. itemSet.add(map); } } // if it is list then return list else return map. if (isList) { return itemSet; } else { return treeMap; } }