@Override public void notifyOfRemovedMetric(final Metric metric, final String metricName, final MetricGroup group) { List<String> dimensionValues = new LinkedList<>(); for (final Map.Entry<String, String> dimension : group.getAllVariables().entrySet()) { dimensionValues.add(labelValueCharactersFilter.filterCharacters(dimension.getValue())); } final String scopedMetricName = getScopedName(metricName, group); synchronized (this) { final AbstractMap.SimpleImmutableEntry<Collector, Integer> collectorWithCount = collectorsWithCountByMetricName.get(scopedMetricName); final Integer count = collectorWithCount.getValue(); final Collector collector = collectorWithCount.getKey(); removeMetric(metric, dimensionValues, collector); if (count == 1) { try { CollectorRegistry.defaultRegistry.unregister(collector); } catch (Exception e) { log.warn("There was a problem unregistering metric {}.", scopedMetricName, e); } collectorsWithCountByMetricName.remove(scopedMetricName); } else { collectorsWithCountByMetricName.put(scopedMetricName, new AbstractMap.SimpleImmutableEntry<>(collector, count - 1)); } } }
@Override public void notifyOfAddedMetric(final Metric metric, final String metricName, final MetricGroup group) { List<String> dimensionKeys = new LinkedList<>(); List<String> dimensionValues = new LinkedList<>(); for (final Map.Entry<String, String> dimension : group.getAllVariables().entrySet()) { final String key = dimension.getKey(); dimensionKeys.add(CHARACTER_FILTER.filterCharacters(key.substring(1, key.length() - 1))); dimensionValues.add(labelValueCharactersFilter.filterCharacters(dimension.getValue())); } final String scopedMetricName = getScopedName(metricName, group); final String helpString = metricName + " (scope: " + getLogicalScope(group) + ")"; final Collector collector; Integer count = 0; synchronized (this) { if (collectorsWithCountByMetricName.containsKey(scopedMetricName)) { final AbstractMap.SimpleImmutableEntry<Collector, Integer> collectorWithCount = collectorsWithCountByMetricName.get(scopedMetricName); collector = collectorWithCount.getKey(); count = collectorWithCount.getValue(); } else { collector = createCollector(metric, dimensionKeys, dimensionValues, scopedMetricName, helpString); try { collector.register(); } catch (Exception e) { log.warn("There was a problem registering metric {}.", metricName, e); } } addMetric(metric, dimensionValues, collector); collectorsWithCountByMetricName.put(scopedMetricName, new AbstractMap.SimpleImmutableEntry<>(collector, count + 1)); } }
.skip(position) .findFirst() .map(entry -> getPoint(new Geoshape(entry.getKey()), entry.getValue())) .orElse(null); default:
public Map<Language, String> getForI18nKey(String i18nKey) { return translations.entrySet().stream() .map(entry -> new SimpleImmutableEntry<>(entry.getKey(), entry.getValue().getTranslation(i18nKey))) .filter(pair -> pair.getValue().isPresent()) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().get())); }
@Override public V get(K key) { AbstractMap.SimpleImmutableEntry<K, V> kvp = cache.getIfPresent(key); if (kvp == null) { return null; } return kvp.getValue(); }
public SortedMap<Integer, String> aggregateTypesOrderedByFrequencyAsSortedMap() { cleanUpOldExceptions(); final Multiset<Class<?>> classes = HashMultiset.create(); for( final SimpleImmutableEntry<ZonedDateTime, Throwable> entry : timestampedThrowables ) { classes.add(entry.getValue().getClass()); } final TreeMap<Integer, String> sortedMap = Maps.newTreeMap(); for( final Class<?> cls : classes.elementSet() ) { sortedMap.put(classes.count(cls), cls.getCanonicalName()); } return sortedMap.descendingMap(); }
void completeComponentProperties(Map<String, String> properties) { componentProperties.forEach(entry -> properties.put(entry.getKey(), extractAssetMetadata(entry.getValue(), properties))); String dbValue = properties.getOrDefault(calciteProperties.get(0), ""); String tableValue = properties.getOrDefault(calciteProperties.get(1), ""); properties.put(calciteProperties.get(0), dbValue); properties.put(calciteProperties.get(1), tableValue); }
private static String rewrite (String text, SimpleImmutableEntry<Pattern,String>[] patterns) { String x = text; Matcher m; for (SimpleImmutableEntry<Pattern,String> pair : patterns) x = pair.getKey().matcher(x).replaceAll(pair.getValue()); return x.trim(); }
private static String getPayloadOxum(final Bag bag){ for(final SimpleImmutableEntry<String,String> keyValue : bag.getMetadata().getAll()){ if("Payload-Oxum".equals(keyValue.getKey())){ return keyValue.getValue(); } } return null; }
private static void writeResults (BufferedWriter writer, String query, KBest kbest) throws Exception { DecimalFormat formatter = new DecimalFormat("#.####"); for (SimpleImmutableEntry<String,Double> pair : kbest.toArray()) { writer.write(query + "\t" + pair.getKey() + "\t" + formatter.format(pair.getValue())); writer.newLine(); } }
@Override public V get(K key) { AbstractMap.SimpleImmutableEntry<K, V> kvp = cache.getIfPresent(key); if (kvp == null) { return null; } return kvp.getValue(); }
@Override public Map<String, String> getNamespaces() { final Map<String, String> namespaces = new HashMap<>(); jdbi.useHandle(handle -> handle.select("SELECT prefix, namespace FROM namespaces") .map((rs, ctx) -> new SimpleImmutableEntry<>(rs.getString("prefix"), rs.getString("namespace"))) .forEach(pair -> namespaces.put(pair.getKey(), pair.getValue()))); return namespaces; }
private ImmutableMap<String, OntopBinding> computeVariable2BindingMap() { this.variableName2BindingMap = Optional.of( signature.stream() .map(s -> new AbstractMap.SimpleImmutableEntry(s, computeBinding(s))) .filter(e -> e.getValue() != null) .collect(ImmutableCollectors.toMap()) ); return variableName2BindingMap.get(); }
public List<String> dump() { cleanUpOldExceptions(); final ImmutableList.Builder<String> builder = ImmutableList.builder(); for( final SimpleImmutableEntry<ZonedDateTime, Throwable> entry : timestampedThrowables ) { builder.add(entry.getKey() + " " + entry.getValue()); } return builder.build(); }
clientCert = clientTLSProps.getValue(); clientKey = clientTLSProps.getKey();
/** * Splits the query string in * * @param url * @return */ Map<String, String> getParametersFromUrl(String url) { // url.getQuery won't work on file addresses int idx = url.indexOf("?"); if (idx == -1 || idx == url.length() - 1) { return Collections.emptyMap(); } String query = url.substring(idx + 1); return Arrays.stream(query.split("&")) .map(this::splitQueryParameter) .filter(e -> e.getValue() != null) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (v1, v2) -> v2)); }
/** * Splits the query string in * * @param url * @return */ Map<String, String> getParametersFromUrl(String url) { // url.getQuery won't work on file addresses int idx = url.indexOf("?"); if (idx == -1 || idx == url.length() - 1) { return Collections.emptyMap(); } String query = url.substring(idx + 1); return Arrays.stream(query.split("&")) .map(this::splitQueryParameter) .filter(e -> e.getValue() != null) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (v1, v2) -> v2)); }
@Override public SimpleImmutableEntry<String, Integer> visit(Node node) { @SuppressWarnings("unchecked") SimpleImmutableEntry<String, Integer> leftResult = (SimpleImmutableEntry<String, Integer>) node.left().accept(this); @SuppressWarnings("unchecked") SimpleImmutableEntry<String, Integer> rightResult = (SimpleImmutableEntry<String, Integer>) node.right().accept(this); int leftDepth = leftResult.getValue(); int rightDepth = rightResult.getValue(); return leftDepth >= rightDepth ? new SimpleImmutableEntry<>(leftResult.getKey(), 1 + leftDepth) : new SimpleImmutableEntry<>(rightResult.getKey(), 1 + rightDepth); } }
@Property public void deepestLeafConstrained( @From(TreeMaker.class) @Depth(min = 10, max = 10) Tree t) { TreeDeepestLeafVisitor visitor = new TreeDeepestLeafVisitor(); @SuppressWarnings("unchecked") SimpleImmutableEntry<String, Integer> result = (SimpleImmutableEntry<String, Integer>) t.accept(visitor); assertThat(result.getValue(), lessThanOrEqualTo(10)); }
@GET @Path("{token}/update/{pin}") @Consumes(value = MediaType.APPLICATION_JSON) @Metric(HTTP_UPDATE_PIN_DATA) public Response updateWidgetPinDataViaGet(@PathParam("token") String token, @PathParam("pin") String pinString, @QueryParam("value") String[] pinValues, @EnumQueryParam(WidgetProperty.class) AbstractMap.SimpleImmutableEntry<WidgetProperty, String> widgetProperty) { if (pinValues != null) { return updateWidgetPinData(token, pinString, pinValues); } if (widgetProperty != null) { return updateWidgetProperty(token, pinString, widgetProperty.getKey(), widgetProperty.getValue()); } return badRequest("Wrong request format."); }