List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:org.apache.hadoop.chukwa.inputtools.mdl.TorqueInfoProcessor.java
private void process_data() throws SQLException { long currentTime = System.currentTimeMillis(); currentTime = currentTime - currentTime % (60 * 1000); Timestamp timestamp = new Timestamp(currentTime); Set<String> hodIds = currentHodJobs.keySet(); Iterator<String> hodIdsIt = hodIds.iterator(); while (hodIdsIt.hasNext()) { String hodId = hodIdsIt.next(); TreeMap<String, String> aJobData = currentHodJobs.get(hodId); String status = aJobData.get("status"); String process = aJobData.get("process"); if (process.equals("0") && (status.equals("R") || status.equals("E"))) { try { boolean result = loadQstatData(hodId); if (result) { aJobData.put("process", "1"); currentHodJobs.put(hodId, aJobData); }// w ww . jav a 2s . c o m } catch (IOException ioe) { log.error("load qsat data Error:" + ioe.getMessage()); } } if (!process.equals("2") && status.equals("C")) { try { boolean result = loadTraceJobData(hodId); if (result) { aJobData.put("process", "2"); currentHodJobs.put(hodId, aJobData); } } catch (IOException ioe) { log.error("loadTraceJobData Error:" + ioe.getMessage()); } } // if } // while }
From source file:org.apache.storm.metricstore.rocksdb.RocksDbMetricsWriter.java
private void processBatchInsert(TreeMap<RocksDbKey, RocksDbValue> batchMap) throws MetricException { try (WriteBatch writeBatch = new WriteBatch()) { // take the batched metric data and write to the database for (RocksDbKey k : batchMap.keySet()) { RocksDbValue v = batchMap.get(k); writeBatch.put(k.getRaw(), v.getRaw()); }//from w w w .ja v a 2 s .c om store.db.write(writeOpts, writeBatch); } catch (Exception e) { String message = "Failed to store data to RocksDB"; LOG.error(message, e); throw new MetricException(message, e); } }
From source file:org.apache.hadoop.dfs.TestDFSUpgradeFromImage.java
private void verifyDir(DFSClient client, String dir) throws IOException { DFSFileInfo[] fileArr = client.listPaths(dir); TreeMap<String, Boolean> fileMap = new TreeMap<String, Boolean>(); for (DFSFileInfo file : fileArr) { String path = file.getPath().toString(); fileMap.put(path, Boolean.valueOf(file.isDir())); }// w w w.ja va 2 s.c o m for (Iterator<String> it = fileMap.keySet().iterator(); it.hasNext();) { String path = it.next(); boolean isDir = fileMap.get(path); overallChecksum.update(path.getBytes()); if (isDir) { verifyDir(client, path); } else { // this is not a directory. Checksum the file data. CRC32 fileCRC = new CRC32(); FSInputStream in = client.open(path); byte[] buf = new byte[4096]; int nRead = 0; while ((nRead = in.read(buf, 0, buf.length)) > 0) { fileCRC.update(buf, 0, nRead); } verifyChecksum(path, fileCRC.getValue()); } } }
From source file:com.deliciousdroid.client.DeliciousApi.java
/** * Performs an api call to Delicious's http based api methods. * /* w w w. j a va 2s. c o m*/ * @param url URL of the api method to call. * @param params Extra parameters included in the api call, as specified by different methods. * @param account The account being synced. * @param context The current application context. * @return A String containing the response from the server. * @throws IOException If a server error was encountered. * @throws AuthenticationException If an authentication error was encountered. */ private static InputStream DeliciousApiCall(String url, TreeMap<String, String> params, Account account, Context context) throws IOException, AuthenticationException { final AccountManager am = AccountManager.get(context); if (account == null) throw new AuthenticationException(); final String username = account.name; String authtoken = null; try { authtoken = am.blockingGetAuthToken(account, Constants.AUTHTOKEN_TYPE, false); } catch (OperationCanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AuthenticatorException e) { // TODO Auto-generated catch block e.printStackTrace(); } Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME); builder.authority(DELICIOUS_AUTHORITY); builder.appendEncodedPath(url); for (String key : params.keySet()) { builder.appendQueryParameter(key, params.get(key)); } String apiCallUrl = builder.build().toString(); Log.d("apiCallUrl", apiCallUrl); final HttpGet post = new HttpGet(apiCallUrl); post.setHeader("User-Agent", "DeliciousDroid"); post.setHeader("Accept-Encoding", "gzip"); DefaultHttpClient client = (DefaultHttpClient) HttpClientFactory.getThreadSafeClient(); CredentialsProvider provider = client.getCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(username, authtoken); provider.setCredentials(SCOPE, credentials); client.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); final HttpResponse resp = client.execute(post); final int statusCode = resp.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { final HttpEntity entity = resp.getEntity(); InputStream instream = entity.getContent(); final Header encoding = entity.getContentEncoding(); if (encoding != null && encoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); } return instream; } else if (statusCode == HttpStatus.SC_UNAUTHORIZED) { throw new AuthenticationException(); } else { throw new IOException(); } }
From source file:net.anthonypoon.ngram.correlation.CorrelationReducer.java
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { TreeMap<String, Double> currElement = new TreeMap(); for (Text val : values) { String[] strArray = val.toString().split("\t"); currElement.put(strArray[0], Double.valueOf(strArray[1])); }//from w w w .j a va 2s .c o m double[] currElementPrimitve = new double[upbound - lowbound + 1]; for (Integer i = 0; i <= upbound - lowbound; i++) { if (currElement.containsKey(String.valueOf(lowbound + i - lag))) { currElementPrimitve[i] = currElement.get(String.valueOf(lowbound + i - lag)); } else { currElementPrimitve[i] = 0; } } for (Map.Entry<String, TreeMap<String, Double>> pair : corrTargetArray.entrySet()) { double[] targetElemetPrimitive = new double[upbound - lowbound + 1]; for (Integer i = 0; i <= upbound - lowbound; i++) { if (pair.getValue().containsKey(String.valueOf(lowbound + i))) { targetElemetPrimitive[i] = pair.getValue().get(String.valueOf(lowbound + i)); } else { targetElemetPrimitive[i] = 0; } } Double correlation = new PearsonsCorrelation().correlation(targetElemetPrimitive, currElementPrimitve); if (correlation > threshold) { NumberFormat formatter = new DecimalFormat("#0.000"); context.write(key, new Text(pair.getKey() + "\t" + formatter.format(correlation))); } } }
From source file:com.sfs.whichdoctor.export.writer.AgedDebtorsAnalysisWriter.java
/** * Gets the formatted period breakdown field. * * @param periods the periods//w w w. jav a 2s . c o m * @param group the group * @param format the format * @return the formatted period breakdown field */ private String getFormattedPeriodBreakdownField(final TreeMap<Integer, AgedDebtorsPeriod> periods, final AgedDebtorsBreakdown breakdown, final String format) { StringBuffer field = new StringBuffer(); int i = 1; for (int id : periods.keySet()) { AgedDebtorsPeriod period = periods.get(id); AgedDebtorsPeriod bPeriod = breakdown.getPeriodBreakdown(period); if (StringUtils.equalsIgnoreCase(format, "html")) { field.append("<div style=\"text-align: right\">"); } field.append(Formatter.toCurrency(bPeriod.getTotal(), "$")); if (StringUtils.equalsIgnoreCase(format, "html")) { field.append("</div>"); } if (i < periods.size()) { field.append(this.getKeys().getString("ITEM_SUFFIX")); field.append(this.getKeys().getString("ITEM_DIVIDER")); field.append(this.getKeys().getString("ITEM_PREFIX")); } i++; } return field.toString(); }
From source file:org.apdplat.superword.tools.TextAnalyzer.java
/** * * @param path ??/*from w w w. j a v a 2 s.com*/ * @param limit ??? * @param isTopN ??? */ public static TreeMap<Float, String> sentence(String path, int limit, boolean isTopN) { //? Set<String> fileNames = getFileNames(path); //? Map<String, AtomicInteger> frequency = frequency(fileNames); //? TreeMap<Float, String> sentences = new TreeMap<>(); //?? int count = 0; for (String fileName : fileNames) { try (BufferedReader reader = new BufferedReader( new InputStreamReader(new BufferedInputStream(new FileInputStream(fileName))))) { String line = null; while ((line = reader.readLine()) != null) { if (StringUtils.isBlank(line)) { continue; } // float score = 0; List<String> words = seg(line); for (String word : words) { AtomicInteger fre = frequency.get(word); if (fre == null || fre.get() == 0) { LOGGER.error("????" + line); score = 0; break; } score += 1 / (float) fre.get(); } words.clear(); if (score > 0) { //??? if (sentences.get(score) != null) { continue; } sentences.put(score, line + " <u><i>" + Paths.get(fileName).toFile().getName().replace(".txt", "") + "</i></u>"); count++; if (count >= limit) { if (isTopN) { // sentences.pollFirstEntry(); } else { // sentences.pollLastEntry(); } } } } } catch (IOException ex) { LOGGER.error("??", ex); } } return sentences; }
From source file:org.cloudata.core.client.Row.java
/** * Return Cell object./*from ww w .j a v a 2 s .co m*/ * @param columnName * @param cellKey * @return cell ? */ public Cell getCell(String columnName, Cell.Key cellKey) { TreeMap<Cell.Key, Cell> cellMap = cells.get(columnName); Cell cell = null; if (cellMap == null || (cell = cellMap.get(cellKey)) == null) { return null; } return cell; }
From source file:de.unidue.langtech.teaching.rp.detector.LanguageDetectorWeb1T.java
private void setTextProbability(TreeMap<Double, String> langProbs, Map<String, Double> textLogProbability) { System.out.println("LangProb: " + langProbs); System.out.println("Highest Prob: " + langProbs.lastEntry()); Double previousValue = textLogProbability.get(langProbs.get(langProbs.lastKey())); if (previousValue == null) { previousValue = 0.0;//w w w .j a v a 2 s. c om } textLogProbability.put(langProbs.get(langProbs.lastKey()), 1 + previousValue); System.out.println("TextLogProb: " + textLogProbability); }
From source file:emlab.role.investment.InvestInPowerGenerationTechnologiesRole.java
private double npv(TreeMap<Integer, Double> netCashFlow, double wacc) { double npv = 0; for (Integer iterator : netCashFlow.keySet()) { npv += netCashFlow.get(iterator).doubleValue() / Math.pow(1 + wacc, iterator.intValue()); }// ww w. java 2s. c om return npv; }