List of usage examples for java.util SortedMap values
Collection<V> values();
From source file:ee.ria.xroad.opmonitordaemon.HealthDataMetricsUtil.java
/** * @param registry the metric registry where the gauge should be looked up * @param expectedGaugeName the gauge name to find * @return the found gauge or null if it does not exist *//*w ww. j a v a2 s.c o m*/ static Gauge findGauge(MetricRegistry registry, String expectedGaugeName) { SortedMap<String, Gauge> gauges = registry.getGauges( (name, metric) -> name.matches(HealthDataMetricsUtil.formatMetricMatchRegexp(expectedGaugeName))); if (gauges.size() > 1) { // Should not happen because we use a strict regexp. log.warn("Multiple gauges matched the name " + expectedGaugeName); } return gauges.isEmpty() ? null : gauges.values().iterator().next(); }
From source file:com.pinterest.secor.parser.MessageParser.java
public static List[] listFromJsonSorted(org.json.JSONObject json) { if (json == null) return null; SortedMap map = new TreeMap(); Iterator i = json.keys();/*from ww w .j a v a2 s .c o m*/ while (i.hasNext()) { try { String key = i.next().toString(); //System.out.println(key); String j = json.getString(key); map.put(key, j); } catch (JSONException e) { e.printStackTrace(); } } LinkedList keys = new LinkedList(map.keySet()); LinkedList values = new LinkedList(map.values()); List[] variable = new List[2]; variable[0] = keys; variable[1] = values; return variable; }
From source file:ee.ria.xroad.opmonitordaemon.HealthDataMetricsUtil.java
/** * @param registry the metric registry where the counter should be looked up * @param expectedCounterName the counter name to find * @return the found counter or null if it does not exist */// w w w .ja va 2 s. c om static Counter findCounter(MetricRegistry registry, String expectedCounterName) { SortedMap<String, Counter> counters = registry.getCounters( (name, metric) -> name.matches(HealthDataMetricsUtil.formatMetricMatchRegexp(expectedCounterName))); if (counters.size() > 1) { // Should not happen because we use a strict regexp. log.warn("Multiple counters matched the name " + expectedCounterName); } return counters.isEmpty() ? null : counters.values().iterator().next(); }
From source file:com.cloudera.oryx.kmeans.common.Weighted.java
/** * Sample items from a {@code List<Weighted>} where items with higher weights * have a higher probability of being included in the sample. * //from ww w .ja v a 2s. c o m * @param things The iterable to sample from * @param size The number of items to sample * @return A list containing the sampled items */ public static <T extends Weighted<?>> List<T> sample(Iterable<T> things, int size, RandomGenerator random) { if (random == null) { random = RandomManager.getRandom(); } SortedMap<Double, T> sampled = Maps.newTreeMap(); for (T thing : things) { if (thing.weight() > 0) { double score = Math.log(random.nextDouble()) / thing.weight(); if (sampled.size() < size || score > sampled.firstKey()) { sampled.put(score, thing); } if (sampled.size() > size) { sampled.remove(sampled.firstKey()); } } } return Lists.newArrayList(sampled.values()); }
From source file:ee.ria.xroad.opmonitordaemon.HealthDataMetricsUtil.java
/** * @param registry the metric registry where the histogram should be * looked up/*ww w .j a va 2s.c o m*/ * @param expectedHistogramName the counter name to find * @return the found histogram or null if it does not exist */ static Histogram findHistogram(MetricRegistry registry, String expectedHistogramName) { SortedMap<String, Histogram> histograms = registry.getHistograms((name, metric) -> name .matches(HealthDataMetricsUtil.formatMetricMatchRegexp(expectedHistogramName))); if (histograms.size() > 1) { // Should not happen because we use a strict regexp. log.warn("Multiple histograms matched the name " + expectedHistogramName); } return histograms.isEmpty() ? null : histograms.values().iterator().next(); }
From source file:eu.ggnet.dwoss.redtape.ShippingCostHelper.java
/** * Method to update/refresh the shipping cost of a {@link Document}. * <p>//w w w . j ava 2s. co m * @param doc the {@link Document} entity. * @param shippingCondition the condition on which the shipping cost is calculated */ public static void modifyOrAddShippingCost(Document doc, ShippingCondition shippingCondition) { int amountOfPositions = doc.getPositions(PositionType.UNIT).size(); for (Position position : doc.getPositions(PositionType.PRODUCT_BATCH).values()) { //just quick for the warranty extension. sucks a bit if we ever wouldhave a refurbished id on another product batch if (!StringUtils.isBlank(position.getRefurbishedId())) continue; amountOfPositions += position.getAmount(); } double costs = 0; if (Client.hasFound(ShippingCostService.class)) costs = Client.lookup(ShippingCostService.class).calculate(amountOfPositions, doc.getDossier().getPaymentMethod(), shippingCondition); SortedMap<Integer, Position> positions = doc.getPositions(PositionType.SHIPPING_COST); if (positions.isEmpty()) { PositionBuilder pb = new PositionBuilder().setType(PositionType.SHIPPING_COST).setName("Versandkosten") .setDescription("Versandkosten zu Vorgang: " + doc.getDossier().getIdentifier()).setPrice(costs) .setTax(GlobalConfig.TAX).setAfterTaxPrice(costs + (costs * GlobalConfig.TAX)) .setBookingAccount(Client.lookup(MandatorSupporter.class).loadPostLedger() .get(PositionType.SHIPPING_COST).orElse(-1)); doc.append(pb.createPosition()); } else { Position next = positions.values().iterator().next(); next.setPrice(costs); next.setAfterTaxPrice(costs + (costs * GlobalConfig.TAX)); } }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.JSONGenerator.java
/** * @param node//from ww w .j av a 2 s. c o m * @param opts * @param out * @throws RepositoryException * @throws JSONException * @throws ValueFormatException * @throws IOException */ private static void outputProperties(Node node, ChecksumGeneratorOptions opts, JsonWriter out) throws RepositoryException, ValueFormatException, IOException { Set<String> excludes = opts.getExcludedProperties(); SortedMap<String, Property> props = new TreeMap<String, Property>(); PropertyIterator propertyIterator = node.getProperties(); // sort the properties by name as the JCR makes no guarantees on property order while (propertyIterator.hasNext()) { Property property = propertyIterator.nextProperty(); //skip the property if it is in the excludes list if (excludes.contains(property.getName())) { continue; } else { props.put(property.getName(), property); } } for (Property property : props.values()) { outputProperty(property, opts, out); } }
From source file:com.twitter.ambrose.service.impl.InMemoryStatsService.java
@Override public synchronized Collection<WorkflowEvent> getEventsSinceId(String workflowId, int sinceId) { int minId = sinceId >= 0 ? sinceId + 1 : sinceId; SortedMap<Integer, WorkflowEvent> tailMap = eventMap.tailMap(minId); return tailMap.values(); }
From source file:fr.mycellar.interfaces.web.services.nav.NavigationWebService.java
/** * @param parentKey/* ww w.ja v a 2s .c o m*/ * @param menuPages * @return */ private NavHeaderDescriptor getHeader(String parentKey, SortedMap<Integer, NavDescriptor> menuPages) { for (NavDescriptor navDescriptor : menuPages.values()) { if (navDescriptor instanceof NavHeaderDescriptor) { NavHeaderDescriptor header = (NavHeaderDescriptor) navDescriptor; if (header.getLabel().equals(parentKey)) { return header; } } } return null; }
From source file:cherry.foundation.telno.AreaCodeTableFactoryTest.java
@Test public void test() throws Exception { List<Resource> resources = new ArrayList<>(9); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124070.xls")); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124071.xls")); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124072.xls")); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124073.xls")); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124074.xls")); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124075.xls")); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124076.xls")); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124077.xls")); resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124078.xls")); AreaCodeTableFactory factory = new AreaCodeTableFactory(); factory.setSoumuExcelParser(new SoumuExcelParser()); factory.setResources(resources);/*from w ww.ja v a2 s .c om*/ Trie<String, Integer> trie = factory.getObject(); SortedMap<String, Integer> map = trie.prefixMap("042"); assertEquals(790, map.size()); assertEquals(new TreeSet<Integer>(asList(2, 3, 4)), new TreeSet<>(map.values())); assertEquals(4554 + 5683 + 3400 + 5343 + 5307 + 3000 + 5548 + 4526 + 5330, trie.size()); assertEquals(Trie.class, factory.getObjectType()); assertFalse(factory.isSingleton()); }