List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.nuxeo.runtime.metrics.CsvReporter.java
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { final long timestamp = TimeUnit.MILLISECONDS.toSeconds(clock.getTime()); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { reportGauge(timestamp, entry.getKey(), entry.getValue()); }//from w ww. ja v a 2 s. c o m for (Map.Entry<String, Counter> entry : counters.entrySet()) { reportCounter(timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { reportHistogram(timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Meter> entry : meters.entrySet()) { reportMeter(timestamp, entry.getKey(), entry.getValue()); } for (Map.Entry<String, Timer> entry : timers.entrySet()) { reportTimer(timestamp, entry.getKey(), entry.getValue()); } }
From source file:com.hightail.metrics.rest.NewRelicHTTPv1Reporter.java
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { try {/*w w w.j av a2s. c o m*/ for (Map.Entry<String, Gauge> gaugeEntry : gauges.entrySet()) { doGauge(gaugeEntry.getKey(), gaugeEntry.getValue()); } for (Map.Entry<String, Counter> counterEntry : counters.entrySet()) { String name = counterEntry.getKey(); Counter counter = counterEntry.getValue(); Map<String, Object> componentMetrics = new HashMap<String, Object>(); componentMetrics.put(prefix(name) + "/count", counter.getCount()); postToNewRelic(componentMetrics); } for (Map.Entry<String, Histogram> histogramEntry : histograms.entrySet()) { String name = histogramEntry.getKey(); Snapshot snapshot = histogramEntry.getValue().getSnapshot(); Histogram metric = histogramEntry.getValue(); doHistogramSnapshot(name, snapshot, metric); } for (Map.Entry<String, Meter> meterEntry : meters.entrySet()) { String name = meterEntry.getKey(); Meter meter = meterEntry.getValue(); doMetered(name, meter); } for (Map.Entry<String, Timer> timerEntry : timers.entrySet()) { Timer timer = timerEntry.getValue(); String name = timerEntry.getKey(); Snapshot snapshot = timer.getSnapshot(); doTimerMetered(timer, name); doTimerSnapshot(timer, name, snapshot); } } catch (Exception ex) { logger.error("Could not push metrics to NewRelic via HTTP : ", ex); } }
From source file:com.maxpowered.amazon.advertising.api.SignedRequestsHelper.java
/** * Canonicalize the query string as required by Amazon. * * @param sortedParamMap//w ww .ja v a 2s .c om * Parameter name-value pairs in lexicographical order. * @return Canonical form of query string. */ private String canonicalize(final SortedMap<String, String> sortedParamMap) { if (sortedParamMap.isEmpty()) { return ""; } final StringBuffer buffer = new StringBuffer(); final Iterator<Map.Entry<String, String>> iter = sortedParamMap.entrySet().iterator(); while (iter.hasNext()) { final Map.Entry<String, String> kvpair = iter.next(); buffer.append(percentEncodeRfc3986(kvpair.getKey())); buffer.append("="); buffer.append(percentEncodeRfc3986(kvpair.getValue())); if (iter.hasNext()) { buffer.append("&"); } } final String cannoical = buffer.toString(); return cannoical; }
From source file:org.ajax4jsf.application.DebugOutputMaker.java
private void writeVariables(PrintWriter out, Map vars, String caption) { out.print("<table><caption>"); out.print(caption);// w w w . java2 s. c o m out.println( "</caption><thead><tr><th style=\"width: 10%; \">Name</th><th style=\"width: 90%; \">Value</th></tr></thead><tbody>"); boolean written = false; if (!vars.isEmpty()) { SortedMap map = new TreeMap(vars); Map.Entry entry = null; String key = null; for (Iterator itr = map.entrySet().iterator(); itr.hasNext();) { entry = (Map.Entry) itr.next(); key = entry.getKey().toString(); if (key.indexOf('.') == -1) { out.println("<tr><td>"); out.println(key.replaceAll("<", LT).replaceAll(">", GT)); out.println("</td><td><span class='value'>"); Object value = entry.getValue(); out.println(value.toString().replaceAll("<", LT).replaceAll(">", GT)); out.println("</span>"); try { PropertyDescriptor propertyDescriptors[] = PropertyUtils.getPropertyDescriptors(value); if (propertyDescriptors.length > 0) { out.print("<div class='properties'><ul class=\'properties\'>"); for (int i = 0; i < propertyDescriptors.length; i++) { String beanPropertyName = propertyDescriptors[i].getName(); if (PropertyUtils.isReadable(value, beanPropertyName)) { out.print("<li class=\'properties\'>"); out.print(beanPropertyName + " = " + BeanUtils.getProperty(value, beanPropertyName)); out.print("</li>"); } } out.print("</ul></div>"); } } catch (Exception e) { // TODO: log exception } out.println("</td></tr>"); written = true; } } } if (!written) { out.println("<tr><td colspan=\"2\"><em>None</em></td></tr>"); } out.println("</tbody></table>"); }
From source file:com.tripit.auth.OAuthCredential.java
private String generateSignature(String baseUrl, SortedMap<String, String> args) throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException { String encoding = "UTF-8"; baseUrl = URLEncoder.encode(baseUrl, encoding); StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (Map.Entry<String, String> arg : args.entrySet()) { if (isFirst) { isFirst = false;/*from ww w . j av a2 s.c o m*/ } else { sb.append('&'); } sb.append(URLEncoder.encode(arg.getKey(), encoding)); sb.append('='); sb.append(URLEncoder.encode(arg.getValue(), encoding)); } String parameters = URLEncoder.encode(sb.toString(), encoding); String signatureBaseString = "GET&" + baseUrl + "&" + parameters; String key = (consumerSecret != null ? consumerSecret : "") + "&" + (userSecret != null ? userSecret : ""); String macName = "HmacSHA1"; Mac mac = Mac.getInstance(macName); mac.init(new SecretKeySpec(key.getBytes(encoding), macName)); byte[] signature = mac.doFinal(signatureBaseString.getBytes(encoding)); return new Base64().encodeToString(signature).trim(); }
From source file:hivemall.topicmodel.ProbabilisticTopicModelBaseUDTF.java
protected void forwardModel() throws HiveException { final IntWritable topicIdx = new IntWritable(); final Text word = new Text(); final FloatWritable score = new FloatWritable(); final Object[] forwardObjs = new Object[3]; forwardObjs[0] = topicIdx;/* w ww. ja v a2 s. c om*/ forwardObjs[1] = word; forwardObjs[2] = score; for (int k = 0; k < topics; k++) { topicIdx.set(k); final SortedMap<Float, List<String>> topicWords = model.getTopicWords(k); for (Map.Entry<Float, List<String>> e : topicWords.entrySet()) { score.set(e.getKey().floatValue()); for (String v : e.getValue()) { word.set(v); forward(forwardObjs); } } } logger.info("Forwarded topic words each of " + topics + " topics"); }
From source file:pl.mrwojtek.sensrec.app.HeartRateDialog.java
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(getContext().getMainLooper()); adapter = new DevicesAdapter(); SensorsRecorder recorder = RecordingService.getRecorder(getActivity()); SortedMap<Integer, BleRecorder> bleRecorders = recorder.getBleRecorders(); for (Map.Entry<Integer, BleRecorder> r : bleRecorders.entrySet()) { adapter.add(r.getValue());/*from ww w.j a v a2s .com*/ } final BluetoothManager bluetoothManager = (BluetoothManager) getContext() .getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); if (!bluetoothAdapter.isEnabled()) { Log.w(TAG, "Bluetooth adapter not enabled"); requestEnableBluetooth(); } else { scanLeDevice(true); } }
From source file:test.RowsWithoutColumnIteratorTest.java
@Test public void simpleMacTest() throws Exception { ZooKeeperInstance instance = new ZooKeeperInstance(mac.getInstanceName(), mac.getZooKeepers()); Connector conn = instance.getConnector("root", new PasswordToken(password)); final String table = "simpleMacTest"; TableOperations tops = conn.tableOperations(); if (tops.exists(table)) { tops.delete(table);// w w w. j a v a2 s . c o m } tops.create(table); BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig()); Mutation m = new Mutation("1"); m.put("A", "", ""); bw.addMutation(m); m = new Mutation("2"); m.put("A", "", ""); m.put("B", "", ""); bw.addMutation(m); m = new Mutation("3"); m.put("A", "", ""); m.put("B", "", ""); bw.addMutation(m); m = new Mutation("4"); m.put("C", "", ""); bw.addMutation(m); bw.close(); Scanner s = conn.createScanner(table, new Authorizations()); Map<String, String> options = ImmutableMap.of(RowsWithoutColumnIterator.COLUMNS_TO_IGNORE, "B,D"); IteratorSetting cfg = new IteratorSetting(50, RowsWithoutColumnIterator.class, options); s.addScanIterator(cfg); s.setRange(new Range()); Iterator<Entry<Key, Value>> iter = s.iterator(); Assert.assertTrue(iter.hasNext()); Entry<Key, Value> next = iter.next(); Assert.assertEquals("1", next.getKey().getRow().toString()); SortedMap<Key, Value> values = WholeRowIterator.decodeRow(next.getKey(), next.getValue()); Assert.assertEquals(1, values.size()); Iterator<Entry<Key, Value>> rowValues = values.entrySet().iterator(); Entry<Key, Value> row = rowValues.next(); Assert.assertEquals(0, new Key("1", "A", "").compareTo(row.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS)); Assert.assertEquals(new Value(new byte[0]), row.getValue()); Assert.assertTrue(iter.hasNext()); next = iter.next(); Assert.assertEquals("4", next.getKey().getRow().toString()); values = WholeRowIterator.decodeRow(next.getKey(), next.getValue()); Assert.assertEquals(1, values.size()); rowValues = values.entrySet().iterator(); row = rowValues.next(); Assert.assertEquals(0, new Key("4", "C", "").compareTo(row.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS)); Assert.assertEquals(new Value(new byte[0]), row.getValue()); Assert.assertFalse(iter.hasNext()); }
From source file:org.springframework.security.oauth.provider.CoreOAuthProviderSupport.java
public String getSignatureBaseString(HttpServletRequest request) { SortedMap<String, SortedSet<String>> significantParameters = loadSignificantParametersForSignatureBaseString( request);// w w w. j a va2s. c om //now concatenate them into a single query string according to the spec. StringBuilder queryString = new StringBuilder(); Iterator<Map.Entry<String, SortedSet<String>>> paramIt = significantParameters.entrySet().iterator(); while (paramIt.hasNext()) { Map.Entry<String, SortedSet<String>> sortedParameter = paramIt.next(); Iterator<String> valueIt = sortedParameter.getValue().iterator(); while (valueIt.hasNext()) { String parameterValue = valueIt.next(); queryString.append(sortedParameter.getKey()).append('=').append(parameterValue); if (paramIt.hasNext() || valueIt.hasNext()) { queryString.append('&'); } } } String url = getBaseUrl(request); if (url == null) { //if no URL is configured, then we'll attempt to reconstruct the URL. This may be inaccurate. url = request.getRequestURL().toString(); } url = normalizeUrl(url); url = oauthEncode(url); String method = request.getMethod().toUpperCase(); return new StringBuilder(method).append('&').append(url).append('&') .append(oauthEncode(queryString.toString())).toString(); }
From source file:com.erinors.hpb.server.handler.SortedMapHandler.java
@Override public Object merge(MergingContext context, Object object) { if (!(object instanceof SortedMap)) { return null; }//from w ww . j a v a 2 s . c om SortedMap<Object, Object> source = (SortedMap<Object, Object>) object; SortedMap<Object, Object> result; if (source instanceof UninitializedPersistentSortedMap) { result = new PersistentSortedMap(context.getSessionImplementor(), source); context.addProcessedObject(object, result); } else { SortedMap<Object, Object> map = new TreeMap<Object, Object>(source.comparator()); context.addProcessedObject(object, map); for (Map.Entry<?, ?> entry : source.entrySet()) { map.put(context.merge(entry.getKey()), context.merge(entry.getValue())); } result = map; } return result; }