List of usage examples for java.util TreeMap keySet
public Set<K> keySet()
From source file:hoot.services.command.CommandRunner.java
private void logExec(String pCmdString, Map<String, String> unsortedEnv) { if (_log.isInfoEnabled()) { TreeMap<String, String> env = new TreeMap<String, String>(); env.putAll(unsortedEnv);/*from w ww .j a va 2 s . c o m*/ _log.info("Executing '" + pCmdString + "'"); _log.info("Enviroment:"); FileWriter writer = null; try { if (_log.isDebugEnabled()) { File envvarFile = File.createTempFile("envvars", ".txt"); writer = new FileWriter(envvarFile); _log.debug("ENVVARS will be written to " + envvarFile.getAbsolutePath()); } for (String key : env.keySet()) { _log.info(String.format(" %s", new Object[] { key + "=" + env.get(key) })); if (_log.isDebugEnabled()) writer.write(String.format(" %s%n", new Object[] { key + "=" + env.get(key) })); } if (_log.isDebugEnabled()) writer.close(); } catch (Exception e) { _log.error("Unable to log exec call: " + ExceptionUtils.getStackTrace(e)); } } }
From source file:org.apache.hadoop.hive.ql.exec.ComputationBalancerReducer.java
public void reduce(BytesWritable wrappedKey, Text wrappedValue) { final String _key = ToolBox.getOriginalKey(wrappedKey); if (_key.startsWith(StatsCollectionOperator.FIELDLENGTH_ATTR)) { Integer iValue = Integer.valueOf(wrappedValue.toString()); Integer _reg_ = infoDict.get(_key); if (_reg_ == null) { _reg_ = iValue;/*www . j av a2s. com*/ } else { _reg_ += iValue; } infoDict.put(_key, _reg_); LOG.debug("FieldLength: " + _key + " " + _reg_); } else if (_key.startsWith(StatsCollectionOperator.NULLCOUNTER_ATTR)) { Integer iValue = Integer.valueOf(wrappedValue.toString()); Integer _reg_ = infoDict.get(_key); if (_reg_ == null) { _reg_ = iValue; } else { _reg_ += iValue; } infoDict.put(_key, _reg_); LOG.debug("NullCounter: " + _key + " " + _reg_); } else if (_key.startsWith(StatsCollectionOperator.RECORDSNUM_ATTR)) { Integer iValue = Integer.valueOf(wrappedValue.toString()); stat_num_records += iValue; } else if (_key.startsWith(SampleOperator.SAMPLE_COUNTER_ATTR)) { Integer iValue = Integer.valueOf(wrappedValue.toString()); _sampledRecordNumber_ += iValue; } else if (_key.startsWith(SampleOperator.SAMPLE_DATA_ATTR)) { _testList.add(wrappedValue); } else if (_key.startsWith(HistogramOperator.MCVLIST_ATTR)) { if (mcvList == null) { return; } { StringTokenizer _hst_ = new StringTokenizer(wrappedValue.toString(), ToolBox.hiveDelimiter); String _true_value_ = _hst_.nextToken(); String _true_fre_ = _hst_.nextToken(); TreeMap<String, Integer> _valfre_map_ = mcvList.get(_key); if (_valfre_map_ == null) { _valfre_map_ = new TreeMap<String, Integer>(); _valfre_map_.put(_true_value_, Integer.valueOf(_true_fre_)); mcvList.put(_key, _valfre_map_); } else { Integer _o_fre_ = _valfre_map_.get(_true_value_); if (_o_fre_ == null) { _o_fre_ = Integer.valueOf(0); } _o_fre_ += Integer.valueOf(_true_fre_); _valfre_map_.put(_true_value_, _o_fre_); } if (_valfre_map_.keySet().size() > 512) { ToolBox _tb = new ToolBox(); _tb.compact(_valfre_map_, ToolBox.SortMethod.DescendSort, Integer.valueOf(512)); } } } else if (_key.startsWith(SampleOperator.STATISTICS_SAMPLING_FACTOR_ATTR)) { Integer ax = Integer.valueOf(wrappedKey.toString()); stat_sampled_counter += ax; } }
From source file:com.sfs.whichdoctor.export.writer.ExportWriterBase.java
/** * Builds the export table./*from ww w . j av a2 s . com*/ * * @param headings the headings * @param values the values * @return the string */ protected final String buildExportTable(final Collection<String> headings, final TreeMap<Integer, Collection<String>> values) { final StringBuffer table = new StringBuffer(); final StringBuffer header = new StringBuffer(); for (String heading : headings) { if (header.length() > 0) { header.append(this.getKeys().getString("ITEM_DIVIDER")); } header.append(this.getKeys().getString("HEADERITEM_PREFIX")); header.append(heading); header.append(this.getKeys().getString("HEADERITEM_SUFFIX")); } if (StringUtils.isNotBlank(header.toString())) { table.append(this.getKeys().getString("LIST_BEGINNING")); table.append(this.getKeys().getString("ROW_BEGINNING")); table.append(header.toString()); table.append(this.getKeys().getString("ROW_END")); } final StringBuffer content = new StringBuffer(); for (Integer index : values.keySet()) { Collection<String> row = values.get(index); content.append(this.getKeys().getString("ROW_BEGINNING")); StringBuffer fieldValue = new StringBuffer(); for (String field : row) { if (fieldValue.length() > 0) { fieldValue.append(this.getKeys().getString("ITEM_DIVIDER")); } fieldValue.append(this.getKeys().getString("ITEM_PREFIX")); fieldValue.append(field); fieldValue.append(this.getKeys().getString("ITEM_SUFFIX")); } content.append(fieldValue.toString()); content.append(this.getKeys().getString("ROW_END")); } if (StringUtils.isNotBlank(content.toString())) { table.append(content.toString()); } if (StringUtils.isNotBlank(header.toString())) { table.append(this.getKeys().getString("LIST_END")); } return table.toString(); }
From source file:org.unc.hive.services.rs.ConceptsResource.java
/** * Gets the list of preferred labels for a given scheme. * //from ww w .j a v a2 s . co m * @param schemeName the scheme name, e.g. "nbii" * @return a list of preferred labels, one per line */ @GET @Path("prefLabels") @Produces("text/plain") public String getPrefLabels(@PathParam("schemeName") String schemeName) { StringBuffer prefLabelsBuffer = new StringBuffer(""); SKOSServer skosServer = ConfigurationListener.getSKOSServer(); if (schemeName != null) { TreeMap<String, SKOSScheme> skosSchemes = skosServer.getSKOSSchemas(); for (String s : skosSchemes.keySet()) { if (s.equalsIgnoreCase(schemeName)) { SKOSScheme skosScheme = skosSchemes.get(s); if (skosScheme != null) { Map<String, QName> alphaIndex = skosScheme.getAlphaIndex(); if (alphaIndex != null) { for (String prefLabel : alphaIndex.keySet()) { prefLabelsBuffer.append(prefLabel + "\n"); } } } } } } return prefLabelsBuffer.toString().trim(); }
From source file:org.unc.hive.services.rs.ConceptsResource.java
/** * Gets the list of preferred labels for a given scheme where each * label starts with the specified letters. * // www.j av a2s . com * @param schemeName the scheme name, e.g. "nbii" * @param startLetters the start letters of the labels to be returned * @return a list of preferred labels, one per line */ @GET @Path("prefLabels/{startLetters}") @Produces("text/plain") public String getPrefLabelsStartLetters(@PathParam("schemeName") String schemeName, @PathParam("startLetters") String startLetters) { StringBuffer prefLabelsBuffer = new StringBuffer(""); SKOSServer skosServer = ConfigurationListener.getSKOSServer(); if (schemeName != null && startLetters != null) { TreeMap<String, SKOSScheme> skosSchemes = skosServer.getSKOSSchemas(); for (String s : skosSchemes.keySet()) { if (s.equalsIgnoreCase(schemeName)) { SKOSScheme skosScheme = skosSchemes.get(s); if (skosScheme != null) { TreeMap<String, QName> alphaIndex = skosScheme.getSubAlphaIndex(startLetters); if (alphaIndex != null) { for (String prefLabel : alphaIndex.keySet()) { prefLabelsBuffer.append(prefLabel + "\n"); } } } } } } return prefLabelsBuffer.toString().trim(); }
From source file:com.cyberway.issue.crawler.admin.StatisticsTracker.java
protected void writeMimetypesReportTo(PrintWriter writer) { // header/*from w w w .j a va 2s .c o m*/ writer.print("[#urls] [#bytes] [mime-types]\n"); TreeMap fd = getReverseSortedCopy(getFileDistribution()); for (Iterator i = fd.keySet().iterator(); i.hasNext();) { Object key = i.next(); // Key is mime type. writer.print(Long.toString(((LongWrapper) fd.get(key)).longValue)); writer.print(" "); writer.print(Long.toString(getBytesPerFileType((String) key))); writer.print(" "); writer.print((String) key); writer.print("\n"); } }
From source file:com.cyberway.issue.crawler.admin.StatisticsTracker.java
protected void writeResponseCodeReportTo(PrintWriter writer) { // Build header. writer.print("[rescode] [#urls]\n"); TreeMap scd = getReverseSortedCopy(getStatusCodeDistribution()); for (Iterator i = scd.keySet().iterator(); i.hasNext();) { Object key = i.next();/* ww w .j av a 2 s . c om*/ writer.print((String) key); writer.print(" "); writer.print(Long.toString(((LongWrapper) scd.get(key)).longValue)); writer.print("\n"); } }
From source file:cc.slda.DisplayTopic.java
@SuppressWarnings("unchecked") public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(Settings.HELP_OPTION, false, "print the help message"); options.addOption(OptionBuilder.withArgName(Settings.PATH_INDICATOR).hasArg() .withDescription("input beta file").create(Settings.INPUT_OPTION)); options.addOption(OptionBuilder.withArgName(Settings.PATH_INDICATOR).hasArg() .withDescription("term index file").create(ParseCorpus.INDEX)); options.addOption(OptionBuilder.withArgName(Settings.INTEGER_INDICATOR).hasArg() .withDescription("display top terms only (default - 10)").create(TOP_DISPLAY_OPTION)); String betaString = null;/*from ww w .j a va 2s .com*/ String indexString = null; int topDisplay = TOP_DISPLAY; CommandLineParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); try { CommandLine line = parser.parse(options, args); if (line.hasOption(Settings.HELP_OPTION)) { formatter.printHelp(ParseCorpus.class.getName(), options); System.exit(0); } if (line.hasOption(Settings.INPUT_OPTION)) { betaString = line.getOptionValue(Settings.INPUT_OPTION); } else { throw new ParseException("Parsing failed due to " + Settings.INPUT_OPTION + " not initialized..."); } if (line.hasOption(ParseCorpus.INDEX)) { indexString = line.getOptionValue(ParseCorpus.INDEX); } else { throw new ParseException("Parsing failed due to " + ParseCorpus.INDEX + " not initialized..."); } if (line.hasOption(TOP_DISPLAY_OPTION)) { topDisplay = Integer.parseInt(line.getOptionValue(TOP_DISPLAY_OPTION)); } } catch (ParseException pe) { System.err.println(pe.getMessage()); formatter.printHelp(ParseCorpus.class.getName(), options); System.exit(0); } catch (NumberFormatException nfe) { System.err.println(nfe.getMessage()); System.exit(0); } JobConf conf = new JobConf(DisplayTopic.class); FileSystem fs = FileSystem.get(conf); Path indexPath = new Path(indexString); Preconditions.checkArgument(fs.exists(indexPath) && fs.isFile(indexPath), "Invalid index path..."); Path betaPath = new Path(betaString); Preconditions.checkArgument(fs.exists(betaPath) && fs.isFile(betaPath), "Invalid beta path..."); SequenceFile.Reader sequenceFileReader = null; try { IntWritable intWritable = new IntWritable(); Text text = new Text(); Map<Integer, String> termIndex = new HashMap<Integer, String>(); sequenceFileReader = new SequenceFile.Reader(fs, indexPath, conf); while (sequenceFileReader.next(intWritable, text)) { termIndex.put(intWritable.get(), text.toString()); } PairOfIntFloat pairOfIntFloat = new PairOfIntFloat(); // HMapIFW hmap = new HMapIFW(); HMapIDW hmap = new HMapIDW(); TreeMap<Double, Integer> treeMap = new TreeMap<Double, Integer>(); sequenceFileReader = new SequenceFile.Reader(fs, betaPath, conf); while (sequenceFileReader.next(pairOfIntFloat, hmap)) { treeMap.clear(); System.out.println("=============================="); System.out.println( "Top ranked " + topDisplay + " terms for Topic " + pairOfIntFloat.getLeftElement()); System.out.println("=============================="); Iterator<Integer> itr1 = hmap.keySet().iterator(); int temp1 = 0; while (itr1.hasNext()) { temp1 = itr1.next(); treeMap.put(-hmap.get(temp1), temp1); if (treeMap.size() > topDisplay) { treeMap.remove(treeMap.lastKey()); } } Iterator<Double> itr2 = treeMap.keySet().iterator(); double temp2 = 0; while (itr2.hasNext()) { temp2 = itr2.next(); if (termIndex.containsKey(treeMap.get(temp2))) { System.out.println(termIndex.get(treeMap.get(temp2)) + "\t\t" + -temp2); } else { System.out.println("How embarrassing! Term index not found..."); } } } } finally { IOUtils.closeStream(sequenceFileReader); } return 0; }
From source file:com.impetus.ankush2.framework.monitor.AbstractMonitor.java
/** * Method to convert null value maps to list object. * //from ww w .j av a 2s .c o 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; } }
From source file:subsets.GenerateGFKMatrix.java
public void part_tree(TreeMap<String, HashSet> treemap_hashset, TreeMap<String, JSONObject> treemap_previous_jsonobject, TreeMap<String, JSONObject> treemap_next_jsonobject, boolean atbottom) { try {/*from w w w. j a v a 2s .c o m*/ for (String head : treemap_hashset.keySet()) { JSONObject json_head = new JSONObject(); json_head.append("name", head.toString()); HashSet hashset = treemap_hashset.get(head); Iterator it = hashset.iterator(); while (it.hasNext()) { String leave = (String) it.next(); JSONObject json_leave = new JSONObject(); if (atbottom) { json_leave.append("name", leave); json_head.append("children", json_leave); } else { JSONObject jsononject_leave = treemap_previous_jsonobject.get(leave); if (jsononject_leave != null) { json_head.append("children", jsononject_leave); } else { JSONObject dummy = new JSONObject(); dummy.append("name", leave); json_head.append("children", dummy); } } } treemap_next_jsonobject.put(head, json_head); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }